通过证明Json对象来获取Json数组



朋友们好,这是我的json数据:

{
   "menus":[
      {
         "id":15,
         "color":"#A67A37",
         "communications":[
            {
               "id":16,
               "projectname":"Sales Training",
               "showpdfprint":false,
               "sendcategory":"document",
               "opened":1
            }
         ],
         "seminars":[
         ],
         "name":"Selective Retail Academy"
      }      "communications":[
         {
            "id":17,
            "projectname":"Sales Education",
            "showpdfprint":false,
            "sendcategory":"document",
            "opened":1
         }
      ],
      "seminars":[
      ],
      "name":"Retail Academy"
   }
}
]

我想检索通信数组提供的名称,我如何在android中实现这一点

使用组织。json库:

JSONObject jObject = new JSONObject(jsonContent); //jsonContent is your content above as a string
JSONArray jArray = jObject.getJSONArray("menus");
JSONArray result;
for(JSONObject jObj : jArray){
    if(jObj.getString("name").equals(givenName){ //givenName is the name you are looking for
        result = jObj.getJSONArray("communications");
    }
}

然后,您可以对存储在"result"中的通信JSONArray执行您喜欢的操作。"

你可以在网站上看到更多。这里的Json库:http://www.json.org/javadoc/org/json/package-summary.html

试试这个伪代码JSON对象

认为这是java的伪代码

最新更新