Get Key and values from JSONObject

前端 未结 3 1116
半阙折子戏
半阙折子戏 2020-12-18 02:30

I am trying to extract Key and values from my JSONObject. But i am not able to do that. Here is the JSON:

[{\"id\":[\"5\"]},{\"Tech\":[\"Java\"]}]

3条回答
  •  情歌与酒
    2020-12-18 02:48

    Parameter you are sending is JsonArray and referring to JsonObject. The Correct way is

    JSONObject jsonObj = new JSONObject("{'id':['5','6']},{'Tech':['Java']}");      
        System.out.println(jsonObj.getString("id"));
    
        JSONArray jsonArray = new JSONArray("[{'id':['5','6','7','8']},{'Tech':['Java']}]");
        System.out.println(jsonArray.length());
        for(int i=0;i

提交回复
热议问题