![](/img/trans.png)
[英]Value 207 at userid of type java.lang.Integer cannot be converted to JSONObject
[英]java.lang.Integer cannot be converted to JSONObject
我以JSON格式从PHP获取状态,但始终得到:
org.json.JSONException: Value 43 of type java.lang.Integer cannot be converted to JSONObject
我的阅读方式来自JSON
int strUserID;
......
strUserID = jsonObject.getInt("UserID");
在PHP我正在使用:
$user_id = mysql_insert_id();
echo $user_id;
if(!$objQuery)
{
$arr['StatusID'] = "0"; // unable to create user
}
else
{
$arr['StatusID'] = "1"; // user created successfully
$arr['UserID'] = $user_id; // passing user id to android app
}
网上的JSON示例:
46{"StatusID":"1","UserID":46}
但是在Android方面没有将数据转换为json格式,因为面临异常
我可以知道我在哪里做错了吗?
从PHP返回数据时,您应该使用JSON对其进行编码。 使用以下功能
echo json_encode($ arr);
在你的php文件中删除
echo $user_id;
并在你的其他条件之后使用它
echo json_encode($arr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.