[Android-JSON] Avoid No value exception when service does not return a specific value in json reponse

Normal way to get string value from a json object would be :


well, sometimes this way does not fit. When you don’t know for sure that your service you are requesting is always stable. It may not return some keys for you, and oops you got 

JSONException No value for “missing key”

Here we may need help from other options.

optString(KEY) AND optString(KEY, Fallback_value)



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: