特殊字符问题

发布于 2024-09-30 09:50:15 字数 1675 浏览 3 评论 0原文

我对 HttpPost 的 json 响应有问题,响应包含类似 & 的字符。哎呀;这会导致在创建 jsonobject 或 jsonarray 时生成异常。

有人知道如何解码吗?我必须在请求中添加标头吗?

多谢。

编辑:

我已经使用了 log cat,这是例外

11-02 09:17:54.472: WARN/System.err(1382): org.json.JSONException: Value XXXXXX& hellip; at authors of type java.lang.String cannot be converted to JSONArray
11-02 09:17:54.492: WARN/System.err(1382):     at org.json.JSON.typeMismatch(JSON.java:96)
11-02 09:17:54.492: WARN/System.err(1382):     at org.json.JSONObject.getJSONArray(JSONObject.java:548)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.httpProxy.ResourceManager.getAuthors(ResourceManager.java:127)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.MyJournalGroup$PostResource.doInBackground(MyJournalGroup.java:291)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.MyJournalGroup$PostResource.doInBackground(MyJournalGroup.java:1)
11-02 09:17:54.492: WARN/System.err(1382):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-02 09:17:54.492: WARN/System.err(1382):     at java.lang.Thread.run(Thread.java:1102)

& hellip ; 通过堆栈溢出直接转换

i have a problem with a json response of an HttpPost , the resposnse contains character like & hellip; and this cause to generate an exception while creating the jsonobject or a jsonarray.

Anyone knows how decode it? i have to add an header in the request?

thanks a lot.

edit:

i already used log cat and this is the exception

11-02 09:17:54.472: WARN/System.err(1382): org.json.JSONException: Value XXXXXX& hellip; at authors of type java.lang.String cannot be converted to JSONArray
11-02 09:17:54.492: WARN/System.err(1382):     at org.json.JSON.typeMismatch(JSON.java:96)
11-02 09:17:54.492: WARN/System.err(1382):     at org.json.JSONObject.getJSONArray(JSONObject.java:548)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.httpProxy.ResourceManager.getAuthors(ResourceManager.java:127)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.MyJournalGroup$PostResource.doInBackground(MyJournalGroup.java:291)
11-02 09:17:54.492: WARN/System.err(1382):     at org.liquidjournal.MyJournalGroup$PostResource.doInBackground(MyJournalGroup.java:1)
11-02 09:17:54.492: WARN/System.err(1382):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-02 09:17:54.492: WARN/System.err(1382):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-02 09:17:54.492: WARN/System.err(1382):     at java.lang.Thread.run(Thread.java:1102)

& hellip ; is converted directly by stack overflow

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-10-07 09:50:15

也许这不是编码问题:从我看到的错误日志中,您尝试将 String 转换为 JSONArray。我不是 JSON 领域的专家,但 JSONArray 是一个集合,我希望您尝试将字符串(包括椭圆字符)添加到(现有的)JSON 数组,而不是尝试从字符串创建数组。

JSON 期望所有字符串均为 UTF-8 格式,因此它确实应该能够处理椭圆字符。

Maybe it's not an encoding problem: from the error log I see, that you try to convert a String to a JSONArray. I'm not an expert in the JSON domain, but a JSONArray is a collection and I'd expect that you try to add the String (including the ellipse char) to the (existing) JSON array rather then trying to make an array from the String.

JSON expects all Strings to be in UTF-8 format, so it really should be able to handle the ellipse char.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文