如何解决java.lang.String无法转换为JSON对象的问题? [英] How do I solved java.lang.String cannot converted to JSON object?
本文介绍了如何解决java.lang.String无法转换为JSON对象的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对android
和MySQL
抱有宽容,并且对此网站有看法:
I have lerant about android
and MySQL
, and I have view about this web:http://codeoncloud.blogspot.tw/2013/07/android-mysql-php-json-tutorial.html
但是我不知道如何解决这个问题: 在此处输入图片描述
but I don't know how to solve this problem: enter image description here
<?php
$host="sql113.byethost14.com"; //replace with database hostname
$username=" xxx "; //replace with database username
$password=" xxx "; //replace with database password
$db_name="b14_16972597_food"; //replace with database name
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "select * from emp_info";
$result = mysql_query($sql);
$json = array();
if(mysql_num_rows($result)){
while($row=mysql_fetch_assoc($result)){
$json['emp_info'][]=$row;
}
}
mysql_close($con);
echo json_encode($json);
?>
推荐答案
您可以通过返回有效的JSON
字符串来解决此问题.
You solve this by returning a valid JSON
string.
您可以使用服务来检查其有效性:
You can use a service to check its validity:
您的脚本应返回JSON
,并且仅返回JSON
字符串.
Your script should return JSON
and only a JSON
string nothing else.
要在您的应用中对此进行调试,您应该记录该字符串并检查它,甚至尝试将其转换为JSON
.
To debug this in your app you should log the string and check it before even attempting to convert it JSON
.
这篇关于如何解决java.lang.String无法转换为JSON对象的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文