I am new to Gson parsing ,did some examples , but this time my json is much complex it looks like this
{
"message": "Ok",
"code": 200,
"data": {
"storage": {
"39": {
"weight": 22000,
"verificationPackageRequested": null,
"id": 39,
"countryCode": "US",
"photosPackageRequested": null,
"created": "2014-12-30 11:27:57",
"ItemPrice": 224.99,
"ItemTitle": "Apple iPad Mini MF432LL/A (16GB, Wi-Fi, Space Gray )",
"PhotoThumbnail": "/upload/storage-products/b8c2839010a8c5aae21df3b9e57125d0_photoThumbnail.jpg"
"items": [
{
"weight": 22000,
"verificationPackageRequested": null,
"id": 39,
"countryCode": "US",
"photosPackageRequested": null,
"created": "2014-12-30 11:27:57",
"ItemPrice": 224.99,
"ItemTitle": "Apple iPad Mini MF432LL/A (16GB, Wi-Fi, Space Gray )",
"PhotoThumbnail": "/upload/storage-products/b8c2839010a8c5aae21df3b9e57125d0_photoThumbnail.jpg"
}
],
"cellStatus": null,
"orderStorageIsMfPackage": 0,
"storageImage": "/upload/storage/storage_6_thumbnail.jpg"
}
}
},
"error": false
}
i tried this way
static class Page{
String message;
int code;
Data data;
//getters+setters
}
static class Data{
HashMap<Values,String> storage;
}
static class Values{
String PhotoThumbnail;
String ItemTitle;
String showPrice;
String weight;
String symbol;
String created;
String id;
String photosPackageRequested;
String verificationPackageRequested;
String countryCode;
//getters+setters
@Override
public String toString(){
return PhotoThumbnail+ " - "+ItemTitle+" - "+showPrice+" - "+weight+" - "+symbol+" - "+created+" - "+id+" - "+photosPackageRequested+" - "+verificationPackageRequested+" -"+countryCode;
}
}
}
And pass results like this
Gson gson = new GsonBuilder().create();
Page wp=gson.fromJson(json,Page.class) ;
But all the i can't get it to work , it show storage as null , i can't understand why , plsease help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…