android 读取json数据(遍历JSONObject和JSONArray)(转)
2014-05-06 11:44
459 查看
public String getJson(){
String jsonString = "{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";//json字符串
try {
JSONObject result = new JSONObject(jsonstring);//转换为JSONObject
int num = result.length();
JSONArray nameList = result.getJSONArray("name");//获取JSONArray
int length = nameList.length();
String aa = "";
for(int i = 0; i < length; i++){//遍历JSONArray
Log.d("debugTest",Integer.toString(i));
JSONObject oj = nameList.getJSONObject(i);
aa = aa + oj.getString("name")+"|";
}
Iterator<?> it = result.keys();
String aa2 = "";
String bb2 = null;
while(it.hasNext()){//遍历JSONObject
bb2 = (String) it.next().toString();
aa2 = aa2 + result.getString(bb2);
}
return aa;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
原文: http://zhaojianping.blog.51cto.com/725123/629526
String jsonString = "{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";//json字符串
try {
JSONObject result = new JSONObject(jsonstring);//转换为JSONObject
int num = result.length();
JSONArray nameList = result.getJSONArray("name");//获取JSONArray
int length = nameList.length();
String aa = "";
for(int i = 0; i < length; i++){//遍历JSONArray
Log.d("debugTest",Integer.toString(i));
JSONObject oj = nameList.getJSONObject(i);
aa = aa + oj.getString("name")+"|";
}
Iterator<?> it = result.keys();
String aa2 = "";
String bb2 = null;
while(it.hasNext()){//遍历JSONObject
bb2 = (String) it.next().toString();
aa2 = aa2 + result.getString(bb2);
}
return aa;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
原文: http://zhaojianping.blog.51cto.com/725123/629526
相关文章推荐
- android 读取JSON数据(遍历JSONObject和JSONArray)
- android 读取JSON数据(遍历JSONObject和JSONArray)
- android 读取json数据(遍历JSONObject和JSONArray
- android 读取json数据(遍历JSONObject和JSONArray)
- android 读取JSON数据(遍历JSONObject和JSONArray)
- android 读取json数据(遍历JSONObject和JSONArray)
- android 读取json数据(遍历JSONObject和JSONArray)
- android 读取json数据(遍历JSONObject和JSONArray
- android 读取JSON数据(遍历JSONObject和JSONArray) .
- android 读取json数据(遍历JSONObject和JSONArray)
- Android 读取 json 数据(遍历jsonarray和jsonboject)-FenGKun
- android JSONArray JSONObject 字符串转json数组 遍历json对象
- Android-JSONObject对JSON数据进行创建和读取的操作-刘宇
- android用JSONObject和JSONArray解析json格式数据
- Android JsonObject 数据的遍历
- json 的解析-使用Android中的JSONObject和JSONArray解析json数据
- json 的解析-使用Android中的JSONObject和JSONArray解析json数据,gson中的JsonReader解析json数据
- Android中的JSONObject和JSONArray解析json数据
- 【Xamarin开发 Android 系列 12】 创建一个Json读取数据应用-添加定位服务
- Android---读取与创建JSON格式的数据