JSonException With Null Value
I'm having lots of problems when parsing a JSon and one of it's values has null value. { 'available_from' : '2012-11-05T00:00:00Z', 'available_to' : '2012-11-30T00:00:00Z', 'catego
Solution 1:
Before trying to get a value from the JSONObject you need to check if it has the key and if the value is not "null".
Add this If statement every time you try to access a certain key:
JSONObject jsonObject = new JSONObject(str);
if(jsonObject.has("category_id")&&!jsonObject.isNull("category_id")){
String s = jsonObject.getString("category_id");
}
Solution 2:
Considered using GSON? It really simplifies JSON parsing. Also if you are using regular jsonobjects the values may not be null. Read the documentation for further info.
Post a Comment for "JSonException With Null Value"