json文字列をjsonオブジェクトに変換

527 ワード

///json   ->json  
 @Test
 public void json2Object() throws JSONException{
  String jsonString = "[{\"a\":\"b1\", \"c\":\"d1\"}, {\"a\":\"b2\", \"c\":\"d2\"}]";  
  JSONArray array = JSONArray.fromObject(jsonString);
  for(int i=0;i<array.size();i++){
   net.sf.json.JSONObject jsonObject = array.getJSONObject(i);
   System.out.println(jsonObject.get("a"));
   System.out.println(jsonObject.get("c"));
  }
 }