需要使用 GSON 类创建 JSONArray 类型
{
"Company":"XYZ Company",
"Cust_Name":"ABC NAME",
"Sector":"SECTOR 1",
"Year":"2017",
"Product_IDs":[
{
"Product_ID":"001",
"JAN":"20",
"Feb":"30",
"MAR":"40"
},
{
"Product_ID":"002",
"JAN":"50",
"Feb":"60",
"MAR":"80"
}
]
}
如何创建 JSONArray 类型任何人都可以帮助我
这样做
ProductM
是您的模型
Type type = new TypeToken<List<ProductM>>() {}.getType();
Gson gson = new Gson();
List<ProductM> tempArr = (List<ProductM>) gson.fromJson(productArray.toString(), type);// productArray -> your product array string
public class ProductM {
@SerializedName("Product_ID")
@Expose
private String productId;
@SerializedName("JAN")
@Expose
private String JAN;
@SerializedName("Feb")
@Expose
private String Feb;
@SerializedName("MAR")
@Expose
private String MAR;
public String getProductId() {
return productId;
}
public String getJAN() {
return JAN;
}
public String getFeb() {
return Feb;
}
public String getMAR() {
return MAR;
}
}
我是一名优秀的程序员,十分优秀!