Display json data to list view

前端 未结 1 1681
庸人自扰
庸人自扰 2021-01-26 04:18

I am trying to display data from JSON array to ListView. But it gives me an exception:

org.json.JSONException: Value [{\"fine_id\":\"51771\",\"st

相关标签:
1条回答
  • 2021-01-26 04:55

    Do the following:

    Change

    JSONObject data = jsonObj.getJSONObject(json); 
    

    to

    JSONArray data = jsonObj.getJSONArray(json);
    

    json is an array, not an object. Thus you are getting an exception.

    Edited:

    for(int i=0; i<data.length(); i++)
    {
         JSONObject obj=data.getJSONObject(i);
         String value1 = obj.getString(FINE_ID); 
            String value2 = obj.getString(WHATEVER YOU WANT); 
            System.out.println(value1);
            System.out.println(value2);
    }
    

    P.S

    [ represents JSON array node
    
    { represents JSON object node
    
    0 讨论(0)
提交回复
热议问题