Parsing JSONObject having dynamic key

后端 未结 4 1565
感情败类
感情败类 2021-01-03 07:34

I have following JSON as response from my server. At first, I thought, it was invalid JSON but after validating it, it seems to be correct:

JOSN: {
    \"cat         


        
4条回答
  •  被撕碎了的回忆
    2021-01-03 08:03

    Try out this code

    JSONObject obj = result.getJSONObject("category");
        Iterator keys = obj.keys();
    
        while (keys.hasNext()) {
            // loop to get the dynamic key
            String dynamicKey = (String) keys.next();
    
            String value= obj.getString(dynamicKey);
        }
    

    For more information checkout this link. May be this will help you more.

提交回复
热议问题