解析数据 org.json.JSONException 时出错:java.lang.String 类型的值 <br 无法转换为 JSONObject

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26870860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:26:55  来源:igfitidea点击:

Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

javaandroidjsonandroid-json

提问by xyz

I am getting this error:

我收到此错误:

Error parsing data org.json.JSONException: Value

解析数据时出错 org.json.JSONException: Value

This is my logcat log:

这是我的 logcat 日志:

11-11 22:47:28.930: D/my(25127): method equals POST is working
11-11 22:47:28.930: D/my(25127): HTTp client is working
11-11 22:47:28.930: D/my(25127): HTTp post is working
11-11 22:47:28.930: D/my(25127): url encoded
11-11 22:47:29.070: D/my(25127): HTTp response is working
11-11 22:47:29.070: D/my(25127): HTTp entity is working
11-11 22:47:29.070: D/my(25127): getcontent is working
11-11 22:47:29.070: D/my(25127): buffer reader crated
11-11 22:47:29.070: D/my(25127): string buffer object crated
11-11 22:47:29.070: D/my(25127): line appended
11-11 22:47:29.070: D/my(25127): inputstram closed
11-11 22:47:29.070: D/my(25127): string buffer to string conversion
11-11 22:47:29.070: E/JSON Parser(25127): Error parsing data org.json.JSONException: Value prepared of type java.lang.String cannot be converted to JSONObject

Error can be in server side script.

错误可能在服务器端脚本中。

The pure JSON response is:

纯 JSON 响应是:

{"success":1,"message":"account successfully created."} 

I have tested it in my browser.

我已经在我的浏览器中测试过了。

采纳答案by xyz

I solved the question myself.

我自己解决了这个问题。

In backend PHP file, I used echostatements, which also outputted as response. So, the json String contained a html tags and/or lines and so, it couldn't be parsed.

在后端 PHP 文件中,我使用了echo语句,它也作为响应输出。因此,json 字符串包含 html 标签和/或行,因此无法解析。

Remove all echostatements or relative statements in your backend file. It will work. Thanks.

删除echo后端文件中的所有语句或相关语句。它会起作用。谢谢。

回答by ToYonos

You json String contains a <br />tag so it can't be parsed.

您 json String 包含一个<br />标签,因此无法解析。

Try you url in a browser and check that the result is pure json.

尝试在浏览器中输入 url 并检查结果是否为纯 json。

回答by Hemant Singh

Convert the string to json object in post execute method.

在 post execute 方法中将字符串转换为 json 对象。