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

时间:2014-02-13 17:11:20

标签: 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, 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的输出首先假设是一个脚本吗?如果不是,那么输出的是什么?

0 个答案:

没有答案