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

后端 未结 5 1079
广开言路
广开言路 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:33

    Use GSON library to parse JSON to java class. It is very simple to use.

    Gson gson = new Gson();
    Response response = gson.fromJson(jsonLine, Users.class);
    

    Generated model example:

       public class Users {
    
           @SerializedName("Users")
           @Expose
           public List Users = new ArrayList();
        }
    
    
        public class User {
    
           @SerializedName("name")
           @Expose
           public String name;
    
           @SerializedName("lon")
           @Expose
           public double lon;
    
           @SerializedName("lat")
           @Expose
           public double lat;
    
       }
    

提交回复
热议问题