Parse json array android

后端 未结 3 1670
渐次进展
渐次进展 2020-12-06 12:59

Hi i\'m trying to parse json array from this url. The json array looks like this.

    [
   {
      \"id\":1,
      \"introtext\":\"\\u041b\\u0438\\u043c\\u04         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 13:42

    You can Easily do it using gson library.

    Here is the code sample:

    Your Entity Class will like:

    public class ResponseEntity {
        @SerializedName("id")
        public int id;
        @SerializedName("introtext")
        public String introtext;
        @SerializedName("image")
        public String image;
        @SerializedName("title")
        public String title;
        @SerializedName("catid")
        public String catid;
        @SerializedName("alias")
        public String alias;
    
    }
    

    Now Convert this json Array using GSON library.

    Gson gson=new Gson();    
        ResponseEntity[] entities = gson.fromJson(yourResponseAsString.toString(),
              ResponseEntity[].class);
    

    Now you have the entity array at entities.

    Thanks.

提交回复
热议问题