2017-02-24 3 views
1

Ineed erstellen JSONArray Typen mit der Gson Klasse erstellenWie ein JSONArray mit Gson in android

{ 

"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" 
    } 
] 

}

wie JSONArray Art zu schaffen, kann jemand mir helfen,

Antwort

0

Gefallen diese

ProductM ist Ihr Modell

 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; 
} 
}