用java怎么把这样的json数据解析成数组?json数据的格式如下:[{"a":"111","b":"222","c":"333"},{"a":"1000","b":"2000","c":"000"},{"a":"999","b":"300","c":"700"}]我希望把a对应的数据全部放到一个数组中,把b对应的数据放到一个数组中,把c对应的数据放到一个数组中,有没有高手会的,求助…………
2 回答
慕妹3242003
TA贡献1824条经验 获得超6个赞
1234567891011121314151617181920212223242526 | import net.sf.json.JSONArray; public class TestJson { public static void main(String []args) { String json = "[{\"a\":\"111\",\"b\":\"222\",\"c\":\"333\"},{\"a\":\"1000\",\"b\":\"2000\",\"c\":\"000\"},{\"a\":\"999\",\"b\":\"300\",\"c\":\"700\"}]" ; JSONArray jsonArr = JSONArray.fromObject(json); String a[] = new String[jsonArr.size()]; String b[] = new String[jsonArr.size()]; String c[] = new String[jsonArr.size()]; for ( int i = 0 ; i < jsonArr.size(); i++) { a[i] = jsonArr.getJSONObject(i).getString( "a" ); b[i] = jsonArr.getJSONObject(i).getString( "b" ); c[i] = jsonArr.getJSONObject(i).getString( "c" ); } for ( int i = 0 ; i < c.length; i++) { System.out.print(a[i]+ " " ); System.out.print(b[i]+ " " ); System.out.print(c[i]); System.out.println(); } } } |
添加回答
举报
0/150
提交
取消