java - Json Parsing and Nullable int value in android -
I have a Jason object as I have shown in two cases: -
Case 1: / P>
{OWNER_ID: 145} case 2:
{OWNER_ID: null} Now I am using the following statement to parse the data:
int note_owner_id = jsonObject.getInt ("OWNER_ID"); I am aware of the fact that in Java, we need to remove an integer number to use the wrapper class and the code should be written as: -
< Pre> integer note_owner_id = jsonObject.getInt ("OWNER_ID"); But still I am not able to parse the data successfully. Can somebody help me out? How to parse a normal value that it will not show an exception?
Thanks in advance. Instead of trying to try to use or handle zero values:
/ Strong>
Try this way, hope it will help you solve your problem.
jsonObject.optInt ("OWNER_ID"); or
jsonObject.optInt ("OWNER_ID", 0);
Comments
Post a Comment