包支持:org.json.jar
第一个:
String js = "{'a':'111','b':'333','c':'666'}";
try {
JSONObject jsonObject01 = new JSONObject(js);
String a = jsonObject01.getString("a");
String b = jsonObject01.getString("b");
String c = jsonObject01.getString("c");
System.out.println(a+b+c);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
第二个:
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)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }