zoukankan      html  css  js  c++  java
  • android 读取json数据(遍历JSONObject和JSONArray)

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

  • 相关阅读:
    将动态aspx页面转换成为静态html页面的几种方法
    IHttpHandler 概述
    .Net,你究竟有多慢
    Js离开提示
    vs2008Webconfig文件
    什么是URL转发和一个IP建多个Web站点主机头名法
    sqlserver 统计sql语句大全收藏
    web.config 读写操作
    httpModules 与 httpHandlers
    简单的介绍一下常用的正规表示式:
  • 原文地址:https://www.cnblogs.com/cnsanshao/p/2145176.html
Copyright © 2011-2022 走看看