JAVA中json读取数组的方法
比如这样一个json包,{"initial":"R","name":"reiz","likes":["JavaScript","Skiing","ApplePie"]}现...
比如这样一个json包,{"initial":"R","name":"reiz","likes":["JavaScript","Skiing","Apple Pie"]}
现在把likes数组提取出来要怎么做?
如果是[{},{},{}]的形式我会做,直接是数组怎么做呢?
eeee 展开
现在把likes数组提取出来要怎么做?
如果是[{},{},{}]的形式我会做,直接是数组怎么做呢?
eeee 展开
2个回答
展开全部
Java语言以JSON的官方库和JSON-lib库来写
取likes是
String t=转义后的{"initial":"R","name":"reiz","likes":["JavaScript","Skiing","Apple Pie"]}
JSONObject jo=new JSONObject(t); //json-lib中是jo=JSONObject.fromObject(t);
JSONArray likes=jo.getJSONArray("likes"); //得到likes数组
System.out.prinlnt(like.getString(2)); //打印Apple Pie
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询