解析数据时出错org.json.JSONException:java.lang.String类型的值<br无法转换为JSONObject
我收到此错误:
解析数据时出错org.json.JSONException:Value
这是我的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
错误可以在服务器端脚本中。
纯JSON响应是:
{"success":1,"message":"account successfully created."}
我在浏览器中测试了它。
我自己解决了这个问题。
在后端PHP文件中,我使用了echo
语句,它也作为响应输出。 因此,json String包含一个html标签和/或行,因此无法解析。
删除后端文件中的所有echo
语句或相关语句。 它会工作。 谢谢。
你json String包含一个
标记,因此无法解析。
在浏览器中尝试使用url并检查结果是否为纯json。
在post execute方法中将字符串转换为json对象。