Reputation: 39
I get ther error when JSON
string have some blank value, getting from server,
how to deal with blank values
here is JSON
{
"status":"success",
"data":[
{
"id":"1",
"name":"ABC",
"address":"ABC, QWE",
"lat":"16.799999",
"lng":"96.150002",
"admin_id":"4",
"is_approved":"1",
"added":"2015-08-07 11:17:12",
"status":"1",
"image_file":"",
"image_width":"",
"image_height":""
}
]
}
Gson gson = new GsonBuilder().serializeNulls().create();
Type listType = new TypeToken<List<MyData>>() {}.getType();
myDataArrayList = gson.fromJson(response.getString("data"), listType);
In MyData class I tried to change lat, long
type int
and changed value in json also for the same but still showing same error
public class MyData implements Parcelable {
public int id;
public String name;
public String address;
public String lat;
public String lng;
public String added;
public int status;
public String image_file;
public int image_width;
public int image_height;
}
Showing error in this line
myDataArrayList = gson.fromJson(response.getString("data"), listType);
Upvotes: 0
Views: 536
Reputation: 941
public int image_width; // Expected integer value while parsing
public int image_height; // Expected integer value while parsing
as you can see below you are having string fields . Initialize below vale to 0
"image_width":0,
"image_height":0
Upvotes: 0
Reputation: 650
Change the type of image_width and image_height to String in MyData Class
public String image_width;
public String image_height;
As int will not be able to store "" this string, and at the time of using it you can parse it into int.
Upvotes: 1