Get json array keys in android

前端 未结 5 1173
渐次进展
渐次进展 2020-12-15 09:16
{
    \"204\": {
        \"host\": \"https:\\/\\/abc.com\\/production-source\\/ChangSha\\/2013\\/12\\/02\\/0\\/0\\/A\\/Content\\/\",
        \"timestamp\": 138590988         


        
5条回答
  •  生来不讨喜
    2020-12-15 09:23

    above sample json array , how to get the 204, 203 and 202?

    No, current String is JSONObject instead of JSONArray. you should get Iterator using JSONObject. keys () if inner JSONObject keys dynamic as:

    JSONObject issueObj = new JSONObject(jsonContent);
    Iterator iterator = issueObj.keys();
       while(iterator.hasNext()){
        String key = (String)iterator.next();
        JSONObject issue = issueObj.getJSONObject(key);
    
        //  get id from  issue
            String _pubKey = issue.optString("id");
        }
    

提交回复
热议问题