Java ArrayList<;字符串>;通过改造android解析为recyclerview
您好,我有一个Java ArrayList<;字符串>;通过改造android解析为recyclerview,java,android,json,android-recyclerview,retrofit,Java,Android,Json,Android Recyclerview,Retrofit,您好,我有一个JSON,但它是一个ArrayList数组。我对这种类型的数组感到困惑。我如何使用改型将这些类型的数组解析为我的recyclerview { "statusCode": 200, "success": true, "message": "Data get succesfully.", "data": [ { "attributes_id": 20, "category_id": "3", "subcategory_id":
JSON
,但它是一个ArrayList
数组。我对这种类型的数组感到困惑。我如何使用改型将这些类型的数组解析为我的recyclerview
{
"statusCode": 200,
"success": true,
"message": "Data get succesfully.",
"data": [
{
"attributes_id": 20,
"category_id": "3",
"subcategory_id": "13",
"product_id": "28",
"attribute_name": "Make",
"isRequired": "yes",
"attribute_type": "dropdown",
"attribute_options": [
"LG",
"Samsung",
"Kelvinetor",
"Haier",
"Wrilphool",
"Other"
],
"created_at": "2019-07-01 12:02:18",
"updated_at": "2019-07-01 12:02:57"
}
]
}
这是我的json
,我尝试将属性_选项列表放入Recyclerview
。
帮帮我
以下是我的回应:
public class GetAttributesResponse {
@SerializedName("statusCode")
@Expose
private int statusCode;
@SerializedName("success")
@Expose
private boolean success;
@SerializedName("message")
@Expose
private String message;
@SerializedName("data")
@Expose
private ArrayList<DataClass> dataclass = null;
public int getStatusCode() {
return statusCode;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public ArrayList<DataClass> getDataclass() {
return dataclass;
}
public void setDataclass(ArrayList<DataClass> dataclass) {
this.dataclass = dataclass;
}
public class DataClass {
@SerializedName("attributes_id")
@Expose
private int attributes_id;
@SerializedName("category_id")
@Expose
private String category_id;
@SerializedName("subcategory_id")
@Expose
private String subcategory_id;
@SerializedName("product_id")
@Expose
private String product_id;
@SerializedName("attribute_name")
@Expose
private String attribute_name;
@SerializedName("isRequired")
@Expose
private String isRequired;
@SerializedName("attribute_type")
@Expose
private String attribute_type;
@SerializedName("created_at")
@Expose
private String created_at;
@SerializedName("updated_at")
@Expose
private String updated_at;
@SerializedName("attribute_options")
@Expose
private ArrayList<String> attribute_options = null;
public int getAttributes_id() {
return attributes_id;
}
public void setAttributes_id(int attributes_id) {
this.attributes_id = attributes_id;
}
public String getCategory_id() {
return category_id;
}
public void setCategory_id(String category_id) {
this.category_id = category_id;
}
public String getSubcategory_id() {
return subcategory_id;
}
public void setSubcategory_id(String subcategory_id) {
this.subcategory_id = subcategory_id;
}
public String getProduct_id() {
return product_id;
}
public void setProduct_id(String product_id) {
this.product_id = product_id;
}
public String getAttribute_name() {
return attribute_name;
}
public void setAttribute_name(String attribute_name) {
this.attribute_name = attribute_name;
}
public String getIsRequired() {
return isRequired;
}
public void setIsRequired(String isRequired) {
this.isRequired = isRequired;
}
public String getAttribute_type() {
return attribute_type;
}
public void setAttribute_type(String attribute_type) {
this.attribute_type = attribute_type;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
public ArrayList<String> getAttribute_options() {
return attribute_options;
}
public void setAttribute_options(ArrayList<String> attribute_options) {
this.attribute_options = attribute_options;
}
}
公共类GetAttributesResponse{
@SerializedName(“状态代码”)
@暴露
专用int状态码;
@序列化名称(“成功”)
@暴露
私人布尔成功;
@SerializedName(“消息”)
@暴露
私有字符串消息;
@SerializedName(“数据”)
@暴露
私有ArrayList数据类=null;
public int getStatusCode(){
返回状态码;
}
公共无效设置状态代码(int状态代码){
this.statusCode=状态码;
}
公共布尔值isSuccess(){
回归成功;
}
public void setSuccess(布尔值成功){
成功=成功;
}
公共字符串getMessage(){
返回消息;
}
公共无效设置消息(字符串消息){
this.message=消息;
}
公共ArrayList getDataclass(){
返回数据类;
}
公共void setDataclass(ArrayList dataclass){
this.dataclass=dataclass;
}
公共类数据类{
@SerializedName(“属性\u id”)
@暴露
私有int属性\u id;
@SerializedName(“类别id”)
@暴露
私有字符串类别_id;
@SerializedName(“子类别\u id”)
@暴露
私有字符串子类别\u id;
@SerializedName(“产品标识”)
@暴露
私有字符串产品标识;
@SerializedName(“属性名称”)
@暴露
私有字符串属性名称;
@SerializedName(“isRequired”)
@暴露
需要私人字符串;
@SerializedName(“属性类型”)
@暴露
私有字符串属性_类型;
@SerializedName(“创建于”)
@暴露
在上创建的私有字符串;
@SerializedName(“更新时间”)
@暴露
私有字符串更新_at;
@SerializedName(“属性_选项”)
@暴露
私有ArrayList属性_options=null;
public int getAttributes_id(){
返回属性\u id;
}
public void setAttributes_id(int attributes_id){
this.attributes\u id=attributes\u id;
}
公共字符串getCategory_id(){
退货类别标识;
}
公共无效集合类别id(字符串类别id){
this.category\u id=category\u id;
}
公共字符串getSubcategory_id(){
返回子类别_id;
}
public void setSubcategory_id(字符串子类别_id){
this.subcategory_id=子类别_id;
}
公共字符串getProduct_id(){
退货产品标识;
}
公共无效设置产品标识(字符串产品标识){
this.product\u id=product\u id;
}
公共字符串getAttribute_name(){
返回属性名称;
}
public void setAttribute_name(字符串属性_name){
this.attribute_name=属性_name;
}
公共字符串getIsRequired(){
需要退货;
}
需要公共无效集(需要字符串){
this.isRequired=isRequired;
}
公共字符串getAttribute_type(){
返回属性类型;
}
公共void集合属性类型(字符串属性类型){
this.attribute_type=属性_type;
}
公共字符串getCreated_at(){
返回创建的时间;
}
公共无效集合创建时间(字符串创建时间){
this.created_at=created_at;
}
公共字符串getUpdated_at(){
返回更新的_地址;
}
公共无效设置日期为(字符串更新日期为){
this.updated_at=updated_at;
}
公共阵列列表getAttribute_options(){
返回属性_选项;
}
公共void setAttribute_选项(ArrayList属性_选项){
this.attribute_options=属性_options;
}
}
}首先需要使用创建JSON到POJO类
package com.test.example;
导入java.util.List;
导入com.google.gson.annotations.Expose;
导入com.google.gson.annotations.SerializedName;
公共类数据{
@SerializedName(“属性\u id”)
@暴露
私有整数属性ID;
@SerializedName(“类别id”)
@暴露
私有字符串类别ID;
@SerializedName(“子类别\u id”)
@暴露
私有字符串子类别ID;
@SerializedName(“产品标识”)
@暴露
私有字符串productId;
@SerializedName(“属性名称”)
@暴露
私有字符串attributeName;
@SerializedName(“isRequired”)
@暴露
需要私人字符串;
@SerializedName(“属性类型”)
@暴露
私有字符串属性类型;
@SerializedName(“属性_选项”)
@暴露
私有列表attributeOptions=null;
@SerializedName(“创建于”)
@暴露
私有字符串createdAt;
@SerializedName(“更新时间”)
@暴露
私有字符串更新数据;
公共整数getAttributesId(){
返回属性ID;
}
public void setAttributesId(整数attributesId){
this.attributesId=attributesId;
}
公共字符串getCategoryId(){
返回类别ID;
}
public void setCategoryId(字符串categoryId){
this.categoryId=categoryId;
}
公共字符串getSubcategorid(){
返回子类别ID;
}
public void setSubcategoryId(字符串子类别ID){
this.subcategoryId=子类别ID;
}
公共字符串getProductId(){
返回productId;
}
public void setProductId(字符串productId){
this.productId=productId;
}
公共字符串getAttributeName(){
返回属性名;
}
公共void setAttributeName(字符串attributeName){
this.attributeName=attributeName;
}
公共字符串getIsRequired(){
需要退货;
}
需要公共无效集(需要字符串){
this.isRequired=isRequired;
}
公共字符串getAttributeType(){
返回属性类型;
}
public void setAttributeType(字符串attributeType){
this.attributeType=attributeType;
}
公共列表getAttributeOptions(){
返回属性;
}
public void setAttributeOptions(列出attributeOptions){
this.attributeOptions=attributeOptions;
}
公共图书馆
package com.test.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Datum {
@SerializedName("attributes_id")
@Expose
private Integer attributesId;
@SerializedName("category_id")
@Expose
private String categoryId;
@SerializedName("subcategory_id")
@Expose
private String subcategoryId;
@SerializedName("product_id")
@Expose
private String productId;
@SerializedName("attribute_name")
@Expose
private String attributeName;
@SerializedName("isRequired")
@Expose
private String isRequired;
@SerializedName("attribute_type")
@Expose
private String attributeType;
@SerializedName("attribute_options")
@Expose
private List<String> attributeOptions = null;
@SerializedName("created_at")
@Expose
private String createdAt;
@SerializedName("updated_at")
@Expose
private String updatedAt;
public Integer getAttributesId() {
return attributesId;
}
public void setAttributesId(Integer attributesId) {
this.attributesId = attributesId;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getSubcategoryId() {
return subcategoryId;
}
public void setSubcategoryId(String subcategoryId) {
this.subcategoryId = subcategoryId;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getAttributeName() {
return attributeName;
}
public void setAttributeName(String attributeName) {
this.attributeName = attributeName;
}
public String getIsRequired() {
return isRequired;
}
public void setIsRequired(String isRequired) {
this.isRequired = isRequired;
}
public String getAttributeType() {
return attributeType;
}
public void setAttributeType(String attributeType) {
this.attributeType = attributeType;
}
public List<String> getAttributeOptions() {
return attributeOptions;
}
public void setAttributeOptions(List<String> attributeOptions) {
this.attributeOptions = attributeOptions;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
package com.test.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class FeasibilityModel {
@SerializedName("statusCode")
@Expose
private Integer statusCode;
@SerializedName("success")
@Expose
private Boolean success;
@SerializedName("message")
@Expose
private String message;
@SerializedName("data")
@Expose
private List<Datum> data = null;
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<Datum> getData() {
return data;
}
public void setData(List<Datum> data) {
this.data = data;
}
}
@GET("//Your End Point URL")
Call<Datum> getList();
call.enqueue(new Callback<List<Hero>>() {
@Override
public void onResponse(Call<Datum> call, Response<Datum> response) {
//In this point we got our hero list
//thats damn easy right ;)
//now we can do whatever we want with this list
}
@Override
public void onFailure(Call<Datum> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});