json java读取

package test;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class StrJson1 {

	public static void main(String[] args) {
		String json = "{'name': '呵呵','array':[{'a':'111','b':'222','c':'333'},{},{'a':'999'}],'address':'上海'}";
		   try {
		    JSONObject jsonObject = new JSONObject(json);
		    String name = jsonObject.getString("name");
		    String address = jsonObject.getString("address");

		    System.out.println("name is:" + name);

		    System.out.println("address is:" + address);
		   
		    JSONArray jsonArray = jsonObject.getJSONArray("array");
		   
		    for (int i = 0; i < jsonArray.length(); i++) {
		     System.out.println("item " + i + " :" + jsonArray.getString(i));
			      try{
			     	JSONObject jsonObject333 = new JSONObject(jsonArray.getString(i));
					String aaaa = jsonObject333.getString("a");
					System.out.println("----------"+aaaa);
			      }catch(Exception e){
				  }
		    }
		   } catch (JSONException e) {
		    e.printStackTrace();
		   }


	}
}

你可能感兴趣的:(java,C++,c,json,C#)