我想解析android中的json字符串。字符串是原樣解析json字符串沒有在整數值中的雙四元組android
String response = "[{"UserID":100055,"VisibleName":"sarita","UserSince":"September 2015"}]";
JSONArray jArray = new JSONArray(response);
for(int i = 0 ; i <jArray.length();i++){
JSONObject jObject = jArray.getJSONObject(i);
}
但在
JSONArray jArray = new JSONArray(response);
org.json.JSONException: Value [{"UserID":100054,"VisibleName":"Sarita","UserSince":"September 2015"}] of type java.lang.String cannot be converted to JSONObject
給出解析例外,我現在用以下進口
進口org.json.JSONArray;
import org.json.JSONObject;
解析沒有問題。 – Rustam
如果你的迴應只是一個字符串變量更新爲'String response =「[{\」UserID \「:100055,\」VisibleName \「:\」sarita \「,\」UserSince \「:\」September 2015 \ }]「;'。如果它是從Web服務的JSON響應然後離開這樣。 – Rustam
使用jsonlint.com來驗證你的json數據。如果出現錯誤,請嘗試解決它。更多的,我建議創建JSON對象,並使用put方法添加數據,如果你使用它作爲本機代碼。 –