String jsonString ={"url":"http://www.cnblogs.com/qianxudetianxia"};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
String url = demoJson.getString("url");
String jsonString ={"name":"android"," version":"Beta1.0"};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
String name = demoJson.getString("name");
String version = demoJson.getString("version");
System.out.println("name:"+name+",version:"+version);
String jsonString ={"number":[1,2,3]};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("number");
for(int i=0; i<numberList.length(); i++){
//因为数组中的类型为int,所以为getInt,其他getString,getLong同用
System.out.println(numberList.getInt(i));
}
String jsonString ={"number":[[1],[2],[3]]};
解析方法:
//嵌套数组遍历
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("number");
for(int i=0; i<numberList.length(); i++){
//获取数组中的数组
System.out.println(numberList.getJSONArray(i).getInt(0));
}
String jsonString ={"swver_info":{"swver":"applite_1.0","allow":true,"next":1429090824,"status":true}};
String mVersion = object.getString("swver");
boolean mAllow = object.getBoolean("allow");
long mTime= object.getLong("next");
boolean mStatus = object.getBoolean("status");
String jsonString ={"mobile":[{"name":"android"},{"name":"iphone"}]};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("mobile");
for(int i=0; i<numberList.length(); i++){
System.out.println(numberList.getJSONObject(i).getString("name"));
}
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
String url = demoJson.getString("url");
String jsonString ={"name":"android"," version":"Beta1.0"};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
String name = demoJson.getString("name");
String version = demoJson.getString("version");
System.out.println("name:"+name+",version:"+version);
String jsonString ={"number":[1,2,3]};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("number");
for(int i=0; i<numberList.length(); i++){
//因为数组中的类型为int,所以为getInt,其他getString,getLong同用
System.out.println(numberList.getInt(i));
}
String jsonString ={"number":[[1],[2],[3]]};
解析方法:
//嵌套数组遍历
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("number");
for(int i=0; i<numberList.length(); i++){
//获取数组中的数组
System.out.println(numberList.getJSONArray(i).getInt(0));
}
String jsonString ={"swver_info":{"swver":"applite_1.0","allow":true,"next":1429090824,"status":true}};
解析方法:
JSONObject Json = new JSONObject(result);
String mVersion = object.getString("swver");
boolean mAllow = object.getBoolean("allow");
long mTime= object.getLong("next");
boolean mStatus = object.getBoolean("status");
String jsonString ={"mobile":[{"name":"android"},{"name":"iphone"}]};
解析方法:
JSONObject demoJson = new JSONObject(jsonString);
JSONArray numberList = demoJson.getJSONArray("mobile");
for(int i=0; i<numberList.length(); i++){
System.out.println(numberList.getJSONObject(i).getString("name"));
}