码迷,mamicode.com
首页 > 移动开发 > 详细

Android 读取 json 数据(遍历jsonarray和jsonboject)-FenGKun

时间:2014-12-08 10:50:21      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:数据   json   遍历   

Android 读取 json 数据(遍历jsonarray和jsonboject)

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);  
        }  
    }  


Android 读取 json 数据(遍历jsonarray和jsonboject)-FenGKun

标签:数据   json   遍历   

原文地址:http://blog.csdn.net/fengkun123/article/details/41799945

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!