What is the difference between
The difference is that
optString returns the empty string (
"") if the key you specify doesn't exist.
getString on the other hand throws a
getString if it's an error for the data to be missing, or
optString if you're not sure if it will be there.
Edit: Full description from the documentation:
Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is not a string and is not null, then it is converted to a string.