How to convert JSONObjects to JSONArray?

后端 未结 4 1787
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 12:12

I have a response like this:

{
 \"songs\":{
          \"2562862600\":{\"id\":\"2562862600\"\"pos\":1},
          \"2562862620\":{\"id\":\"2562862620\"\"pos\"         


        
4条回答
  •  青春惊慌失措
    2020-11-28 12:37

    Your response should be something like this to be qualified as Json Array.

    {
      "songs":[
        {"2562862600": {"id":"2562862600", "pos":1}},  
        {"2562862620": {"id":"2562862620", "pos":1}},  
        {"2562862604": {"id":"2562862604", "pos":1}},  
        {"2573433638": {"id":"2573433638", "pos":1}}
      ]
    }
    

    You can parse your response as follows

    String resp = ...//String output from your source
    JSONObject ob = new JSONObject(resp);  
    JSONArray arr = ob.getJSONArray("songs");
    
    for(int i=0; i

提交回复
热议问题