Whenever I have a Json string object with a space in it I get the following error.
Java:
String jString = getResources().getString(R.string.event);
JSONObject object = new JSONObject(jString);
Json:
<resources>
<string name="event">
{"Array":[{"Name":"One two three"},{"Name":"Two"},{"Name":"Three"}]}
</string>
</resources>
I am get the following message:
09-06 22:35:08.214: WARN/System.err(1079): org.json.JSONException: Unterminated object at character 21 of {Array:[{Name:One two three},{Name:Two},{Name:Three}]}
This doesn't have any issues:
<resources>
<string name="event">
{"Array":[{"Name":"One"},{"Name":"Two"},{"Name":"Three"}]}
</string>
</resources>
Am I quoting something wrong?
EDIT: Reading through my own post I noticed that the error message doesn't have any quotes around the string object values. So I changed the " to \" in the xml string and it worked fine. Any idea how to have it not remove any quotes?
Reading through my own post I noticed that the error message doesn't have any quotes around the string object values. So I changed the " to \" in the xml string and it worked fine.
Try wrapping it in a CDATA block. This should prevent any confusion.
<resources>
<string name="event"><![CDATA[
{"Array":[{"Name":"One two three"},{"Name":"Two"},{"Name":"Three"}]}
]]></string>
</resources>
Space in the JSON creates this issue . TRY following json {"Array":[{"Name":"One-two-three"},{"Name":"Two"},{"Name":"Three"}]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With