I'm developing an Android App which uses JSON for the server communication and I've got a weird problem when I'm trying to parse my json file.
This is my json from the server
{
"street2": null,
"province": null,
"street1": null,
"postalCode": null,
"country": null,
"city": null
}
I'm getting the value for City by calling String city = address.optString("city", "")
on my address Json-object. For this situation I'm expecting city
to be empty (that's what optString is here for isn't it?) but in fact it contains the String "null". So further null- or isEmpty-checks will return false as the String contains text. If I call address.isNull("city")
it returns true which is correct. Only optString
fails.
I couldn't find anything on Google or Stack Overflow for this problem. I don't really understand how it can happen as I thought optString
would do exactly what I expected. Anybody knows what's going wrong here?