org.json.JSONException: Unterminated object at character 14

Not directly related to the question, but I got this error when it was trying to parse malformed json. I was missing a comma between two properties. (Using gson)


The only solution I can find (Android: Json string with spaces gives "Unterminated object at" exception) is to replace the quotes in your json with escaped quotes

<string name="data">{"address": \"yo test\"}</string>

Annoying though. Wonder if there's a better solution.

EDIT:

After a little more digging it looks like the culprit is the getString method which claims to

Return the string value associated with a particular resource ID. It will be stripped of any styled text information.

The stripping of styled text occurs in native code so I cannot see why it throws out the quotes, but looks like it does.

Tags:

Java

Json

Android