2015-09-07 55 views
1

我从PHP读取状态JSON格式,但总是得到:java.lang.Integer中不能被转换为JSONObject的

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格式,因为面临着异常

可我知道我在做什么错误?

+0

可以添加你的'json'回应? – Rustam

+0

发布您的** Json数据**。 – Pankaj

+0

@Rustam检查以上 – Sophie

回答

2

从PHP返回数据时,您应该使用JSON进行编码。 以下使用功能

echo json_encode($ arr);

1

在你的PHP文件中删除

echo $user_id; 

,并用这个你else条件后

echo json_encode($arr); 
+1

你是对的Ravi'user_id'在响应数据中附加。 – Rustam

相关问题