2015-09-07 242 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

相關問題