JSONObject in JSONObject

前端 未结 3 1725
青春惊慌失措
青春惊慌失措 2021-01-04 08:27

I have an API Output like this:

{\"user\" : {\"status\" : {\"stat1\" : \"54\", \"stats2\" : \"87\"}}}

I create a simple JSONObject

3条回答
  •  既然无缘
    2021-01-04 09:27

    JSONObject mJsonObject = new JSONObject(response);
    JSONObject userJObject = mJsonObject.getJSONObject("user");
    JSONObject statusJObject = userJObject.getJSONObject("status");
    String stat1 = statusJObject.getInt("stat1");
    String stats2 = statusJObject.getInt("stats2");
    

    from your response user and status is Object so for that use getJSONObject and stat1 and stats2 is status object key so for that use getInt() method for getting integer value and use getString() method for getting String value.

提交回复
热议问题