I'm trying to get values from Json object and I have a problem. I'm using getint function to get value but the value is null and getint function gving error.
How can I solve this problem?
Code :
firmInfo.setFirmID(object.getInt(Constants.FirmID));
Thanks.
JSON has two types of null value After reaching out it became clear to me that the issue here wasn't specific to Go, but rather a shortcoming of JSON used in conjunction with any typed language. In JSON there are effectively two types of null .
To check null in JavaScript, use triple equals operator(===) or Object is() method. If you want to use Object.is() method then you two arguments. 1) Pass your variable value with a null value. 2) The null value itself.
Using simple java rules. Check if the array is empty, if the array does not exist and you try to get it, it just returns null. Just handle it. Don't continue parsing if you know its going to fail.
Assuming that object
is of type JSONObject
you can use
object.optInt(Constants.FirmID)
or
object.optInt(Constants.FirmID, defaultValue)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With