安卓:JSON字符串用空格给人"未结束的对象AT"例外 [英] Android: Json string with spaces gives "Unterminated object at" exception
问题描述
每当我有一个空间,一个JSON字符串对象是我碰到下面的错误。
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:
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}]}
这没有任何问题:
<resources>
<string name="event">
{"Array":[{"Name":"One"},{"Name":"Two"},{"Name":"Three"}]}
</string>
</resources>
难道我引用什么不对?
Am I quoting something wrong?
编辑:读通过我自己的文章中我注意到,错误消息没有周围的字符串对象值的任何报价。所以我改变了到\中的XML字符串,它能正常工作。不知道如何把它不会删除任何引号?
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?
推荐答案
读通过我自己的文章中我注意到,错误消息没有周围的字符串对象值的任何报价。所以我改变了到\中的XML字符串,它能正常工作。
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.
这篇关于安卓:JSON字符串用空格给人&QUOT;未结束的对象AT&QUOT;例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!