How to parse JSON object from a website into an arraylist in android

后端 未结 5 990
广开言路
广开言路 2021-01-07 09:55

How can I parse a JSON object from a weblink into Android and store the different values into ArrayLists?

The JSON object of users looks like the below. It comes fro

5条回答
  •  隐瞒了意图╮
    2021-01-07 10:20

    You can use the native JSONObject and JSONArray present on the Android SDK here : https://developer.android.com/reference/org/json/JSONObject.html

    There is a method named JSONObject(String json) that allow you to do something like this (not tested) :

    //creating your json object from your strong
    JSONObject jsonObject = new JSONObject(yourString);
    JSONArray users = jsonObject.getJSONArray("users");//this two lines throws a JSONException so put try{}catch{} block
    for(JSON user in users)
    {
            JSONObject currentUser = users.get(i);
            //insert yout user inside your ArrayList here
    }
    

提交回复
热议问题