JAVA中json读取数组的方法

2024-11-17 13:29:53
推荐回答(2个)
回答1:

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

回答2:

请问[{},{},{}]这种格式怎么做