Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将java.lang.String转换为JSONObject_Java_Android_Json_Android Json - Fatal编程技术网

无法将java.lang.String转换为JSONObject

无法将java.lang.String转换为JSONObject,java,android,json,android-json,Java,Android,Json,Android Json,我得到的响应为“成功”,但responseJson值为“null” 这就是我得到的: responseJson = new JSONObject(response); 如果我能得到一个敬礼就好了 提前感谢。请尝试以下代码: Error converting result org.json.JSONException: Value Fail of type java.lang.String cannot be converted to JSONObject 你的回答是什么?您是否尝试输入响应请

我得到的响应为“成功”,但responseJson值为“null”

这就是我得到的:

responseJson = new JSONObject(response);
如果我能得到一个敬礼就好了 提前感谢。

请尝试以下代码:

Error converting result org.json.JSONException: Value Fail of type java.lang.String cannot be converted to JSONObject

你的回答是什么?您是否尝试输入响应请显示来自
httpClient.execute(httpPost,responseHandler)
的响应。我认为您的服务是本地的,因此无法从上面的URL获得broswer的响应。在这里,我也获得了成功的响应。response=httpClient.execute(httpPost,responseHandler);我认为您的响应不是json或无效的json格式。
Error converting result org.json.JSONException: Value Fail of type java.lang.String cannot be converted to JSONObject
Object json = new JSONTokener(response).nextValue();
if (json instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) json;
 // your logic
}else if(json instanceof JSONObject){
//your logic
}