Difference between getString() and optString() in Json
While fetching the data from JSON
, we might have null
data for a particular Key value, at that time instead of implementing Null conditions, better make use of this optimized method optString("<keyname>")
optString("<KeyName>")
returns the empty string (""
) if the key you specify doesn’t exist. On the other hand getString("<KeyName>")
throws a JSONException
Happy to know this………