android 读取json数据(遍历JSONObject和JSONArray)

        
  1. publicStringgetJson(){
  2. StringjsonString="{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";//json字符串
  3. try{
  4. JSONObjectresult=newJSONObject(jsonstring);//转换为JSONObject
  5. intnum=result.length();
  6. JSONArraynameList=result.getJSONArray("name");//获取JSONArray
  7. intlength=nameList.length();
  8. Stringaa="";
  9. for(inti=0;i<length;i++){//遍历JSONArray
  10. Log.d("debugTest",Integer.toString(i));
  11. JSONObjectoj=nameList.getJSONObject(i);
  12. aa=aa+oj.getString("name")+"|";
  13. }
  14. Iterator<?>it=result.keys();
  15. Stringaa2="";
  16. Stringbb2=null;
  17. while(it.hasNext()){//遍历JSONObject
  18. bb2=(String)it.next().toString();
  19. aa2=aa2+result.getString(bb2);
  20. }
  21. returnaa;
  22. }catch(JSONExceptione){
  23. thrownewRuntimeException(e);
  24. }
  25. }

更多相关文章

  1. Android Base64字符串转换成图片
  2. Android Studio如何轻松整理字符串到string.xml中
  3. Android实现DES对字符串加密
  4. Android中判断字符串中必须包含字母或者数字_Android
  5. android 复制、粘贴字符串 (判断API 11 )
  6. android中遍历arrayList的四种方法
  7. Android实现TextView字符串波浪式跳动
  8. Android的数据处理:使用annotation实现JSON字符串解析为java对象

随机推荐

  1. Android 的源代码结构
  2. 条码扫描二维码扫描—ZXing android 改进
  3. android 测试必备 -adb 工具的使用
  4. Android onDraw
  5. 最新android sdk版本号和sdk的对应关系
  6. Android 动画方案
  7. Android Log详解!
  8. [Android] ubuntu 下不识别 Android 设备
  9. [置顶] Android IPC 通讯机制源码分析【
  10. android去掉button默认的点击阴影