简体   繁体   English

使用改造在Android中获取json中的多个数组

[英]get multiple arrays in json in Android using retrofit

How to create a correct pojo class for the below json and display the "mcategory_id" and "effect_list" in textview using Retrofit 2 如何使用Retrofit 2为以下json创建正确的pojo类并在textview中显示“ mcategory_id”和“ effect_list”

     {  
   "categories":[  
  {  

      "mcategory_id":"14"
  }  
                ],

   "effect_list":{  
       "14":[  
  {  
       "effects_id":"164"
  }        
            ]
      }
}

使用此链接创建您的Java文件JsonToJavaConversion

You will have a class Category with attribute mcategory_id. 您将具有一个类别Category,其属性为mcategory_id。 Then you will have a class effect_list which will contain a list of items that contains "effects_id". 然后,您将具有一个effect_list类,该类将包含包含“ effects_id”的项目的列表。 So basically you will need 4 classes. 因此,基本上,您将需要4个课程。

Class Category with mcategory_id. 具有mcategory_id的类类别。

Class Effects with effects_id. 具有effects_id的效果类。

Class Effect_list (in your json is a object not a list) which will contain a list of Effects ("14" name in your json) 类Effect_list(在您的json中是一个对象而不是列表),它将包含一个效果列表(在json中为“ 14”名称)

And a response class for your retrofit: Retrofit class will contain List of Category("categories"called in your json) and a object of Effect_list(called "effect_list" in your json). 还有一个用于改造的响应类:改造类将包含Category列表(在json中称为“类别”)和一个Effect_list对象(在json中称为“ effect_list”)。

Use annotation @SerializedName so that you can map easily the json into your objects. 使用注释@SerializedName,以便您可以轻松地将json映射到对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM