Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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_Json - Fatal编程技术网

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

无法将java.lang.String转换为JSONObject错误,java,json,Java,Json,几天来我一直在试图解决这个问题,但仍然没有任何运气。我是新来的 这是我的JSONParser: public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } public JSONObject makeHttpRequest(String url, S

几天来我一直在试图解决这个问题,但仍然没有任何运气。我是新来的

这是我的JSONParser:

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject makeHttpRequest(String url, String method,
        List<NameValuePair> params) {

    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);          
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}
}
这是错误日志:

02-13 11:43:34.439: E/JSON(948):         <script type="text/javascript">
02-13 11:43:34.439: E/JSON(948):             <!--
02-13 11:43:34.439: E/JSON(948):             window.location = "http://p.pw/404"
02-13 11:43:34.439: E/JSON(948):             //-->
02-13 11:43:34.439: E/JSON(948):         </script>
02-13 11:43:34.439: E/JSON(948):     
02-13 11:43:34.439: E/JSON Parser(948): Error parsing data org.json.JSONException: Value     <script of type java.lang.String cannot be converted to JSONObject

json的输出首先应该是一个脚本吗?如果没有,那么它应该输出什么?

您是否检查了json,它是有效的?呃。。。如何检查?XD您的代码正在检索的uri不正确JSON@firaga这不是json,也不是javascript代码,不是javascript,而是html