在以下json
中有两个产品对象,产品不断变化,有超过100种产品(我尝试了json
到pojo
转换器,但它有两个用于两个主要类别内的产品)......产品是动态的...我正在使用改造
{
"1": {
"entity_id": "11",
"type_id": "virtual",
"sku": "JIG0001VEN",
"name": "Test Chanakya",
"meta_title": "Test Chanakya",
"meta_description": "Test Chanakya",
"brand_name": "Chanakya",
"language": "English",
"no_test_attempts": "4",
"product_type": "25",
"difficulty_level": "20",
"jigno_certified": "18",
"ca_related": "23",
"description": "Test Chanakya",
"short_description": "Test Chanakya",
"meta_keyword": "Test Chanakya",
"regular_price_with_tax": 4500,
"regular_price_without_tax": 4500,
"final_price_with_tax": 4500,
"final_price_without_tax": 4500,
"is_saleable": true
},
"2": {
"entity_id": "12",
"type_id": "virtual",
"sku": "JIG5555GENESIS",
"name": "Genesis Mentors GMAT Mock - 01",
"meta_title": "Genesis GMAT",
"brand_name": "Genesis Mentors",
"language": "English",
"meta_description": "Genesis GMAT",
"no_test_attempts": "3",
"product_type": "25",
"difficulty_level": "21",
"jigno_certified": "18",
"ca_related": "23",
"description": "Exhaustive national level ",
"meta_keyword": "GMAT, Genesis, Management",
"short_description": "Genesis Mentors GMAT Mock",
"regular_price_with_tax": 199,
"regular_price_without_tax": 199,
"final_price_with_tax": 199,
"final_price_without_tax": 199,
"is_saleable": true
}
}
答案 0 :(得分:1)
有两种方法:
第一种方法是使用Gson
您可以在此平台上找到有关how to use Gson
的数千个问题第二种方法是使用Android默认库
您只需拥有一个产品对象列表,因此在使用此库迭代此数组中的每个JSONArray并将其转换为模型后,您需要使用JSONObject。
由于它很容易,我不会发布完整的对象。只需创建一个包含对象中所有值的类,并阅读这些选项。
答案 1 :(得分:1)
您可以通过此链接获取详细信息:: http://www.jsonschema2pojo.org/
或强>
这是解决方案..
package com.example.models;
public class ExampleResponse {
DemoClassForOne _1;
DemoClassForOne _2;
public DemoClassForOne get_1() {
return _1;
}
public void set_1(DemoClassForOne _1) {
this._1 = _1;
}
public DemoClassForOne get_2() {
return _2;
}
public void set_2(DemoClassForOne _2) {
this._2 = _2;
}
public class DemoClassForOne{
private String entityId;
private String typeId;
private String sku;
private String name;
private String metaTitle;
private String metaDescription;
private String brandName;
private String language;
private String noTestAttempts;
private String productType;
private String difficultyLevel;
private String jignoCertified;
private String caRelated;
private String description;
private String shortDescription;
private String metaKeyword;
private Integer regularPriceWithTax;
private Integer regularPriceWithoutTax;
private Integer finalPriceWithTax;
private Integer finalPriceWithoutTax;
private Boolean isSaleable;
/**
*
* @return
* The entityId
*/
public String getEntityId() {
return entityId;
}
/**
*
* @param entityId
* The entity_id
*/
public void setEntityId(String entityId) {
this.entityId = entityId;
}
/**
*
* @return
* The typeId
*/
public String getTypeId() {
return typeId;
}
/**
*
* @param typeId
* The type_id
*/
public void setTypeId(String typeId) {
this.typeId = typeId;
}
/**
*
* @return
* The sku
*/
public String getSku() {
return sku;
}
/**
*
* @param sku
* The sku
*/
public void setSku(String sku) {
this.sku = sku;
}
/**
*
* @return
* The name
*/
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return
* The metaTitle
*/
public String getMetaTitle() {
return metaTitle;
}
/**
*
* @param metaTitle
* The meta_title
*/
public void setMetaTitle(String metaTitle) {
this.metaTitle = metaTitle;
}
/**
*
* @return
* The metaDescription
*/
public String getMetaDescription() {
return metaDescription;
}
/**
*
* @param metaDescription
* The meta_description
*/
public void setMetaDescription(String metaDescription) {
this.metaDescription = metaDescription;
}
/**
*
* @return
* The brandName
*/
public String getBrandName() {
return brandName;
}
/**
*
* @param brandName
* The brand_name
*/
public void setBrandName(String brandName) {
this.brandName = brandName;
}
/**
*
* @return
* The language
*/
public String getLanguage() {
return language;
}
/**
*
* @param language
* The language
*/
public void setLanguage(String language) {
this.language = language;
}
/**
*
* @return
* The noTestAttempts
*/
public String getNoTestAttempts() {
return noTestAttempts;
}
/**
*
* @param noTestAttempts
* The no_test_attempts
*/
public void setNoTestAttempts(String noTestAttempts) {
this.noTestAttempts = noTestAttempts;
}
/**
*
* @return
* The productType
*/
public String getProductType() {
return productType;
}
/**
*
* @param productType
* The product_type
*/
public void setProductType(String productType) {
this.productType = productType;
}
/**
*
* @return
* The difficultyLevel
*/
public String getDifficultyLevel() {
return difficultyLevel;
}
/**
*
* @param difficultyLevel
* The difficulty_level
*/
public void setDifficultyLevel(String difficultyLevel) {
this.difficultyLevel = difficultyLevel;
}
/**
*
* @return
* The jignoCertified
*/
public String getJignoCertified() {
return jignoCertified;
}
/**
*
* @param jignoCertified
* The jigno_certified
*/
public void setJignoCertified(String jignoCertified) {
this.jignoCertified = jignoCertified;
}
/**
*
* @return
* The caRelated
*/
public String getCaRelated() {
return caRelated;
}
/**
*
* @param caRelated
* The ca_related
*/
public void setCaRelated(String caRelated) {
this.caRelated = caRelated;
}
/**
*
* @return
* The description
*/
public String getDescription() {
return description;
}
/**
*
* @param description
* The description
*/
public void setDescription(String description) {
this.description = description;
}
/**
*
* @return
* The shortDescription
*/
public String getShortDescription() {
return shortDescription;
}
/**
*
* @param shortDescription
* The short_description
*/
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
/**
*
* @return
* The metaKeyword
*/
public String getMetaKeyword() {
return metaKeyword;
}
/**
*
* @param metaKeyword
* The meta_keyword
*/
public void setMetaKeyword(String metaKeyword) {
this.metaKeyword = metaKeyword;
}
/**
*
* @return
* The regularPriceWithTax
*/
public Integer getRegularPriceWithTax() {
return regularPriceWithTax;
}
/**
*
* @param regularPriceWithTax
* The regular_price_with_tax
*/
public void setRegularPriceWithTax(Integer regularPriceWithTax) {
this.regularPriceWithTax = regularPriceWithTax;
}
/**
*
* @return
* The regularPriceWithoutTax
*/
public Integer getRegularPriceWithoutTax() {
return regularPriceWithoutTax;
}
/**
*
* @param regularPriceWithoutTax
* The regular_price_without_tax
*/
public void setRegularPriceWithoutTax(Integer regularPriceWithoutTax) {
this.regularPriceWithoutTax = regularPriceWithoutTax;
}
/**
*
* @return
* The finalPriceWithTax
*/
public Integer getFinalPriceWithTax() {
return finalPriceWithTax;
}
/**
*
* @param finalPriceWithTax
* The final_price_with_tax
*/
public void setFinalPriceWithTax(Integer finalPriceWithTax) {
this.finalPriceWithTax = finalPriceWithTax;
}
/**
*
* @return
* The finalPriceWithoutTax
*/
public Integer getFinalPriceWithoutTax() {
return finalPriceWithoutTax;
}
/**
*
* @param finalPriceWithoutTax
* The final_price_without_tax
*/
public void setFinalPriceWithoutTax(Integer finalPriceWithoutTax) {
this.finalPriceWithoutTax = finalPriceWithoutTax;
}
/**
*
* @return
* The isSaleable
*/
public Boolean getIsSaleable() {
return isSaleable;
}
/**
*
* @param isSaleable
* The is_saleable
*/
public void setIsSaleable(Boolean isSaleable) {
this.isSaleable = isSaleable;
}
}
}
只需复制并粘贴&重命名.. 之后,您可以使用get& amp;设定方法...... 欢迎欣赏......
答案 2 :(得分:0)
http://json2csharp.com/#查看此链接并复制您的json以获取您的模式