dsa88886666 2014-02-17 20:25
浏览 253
已采纳

继续解析数据的错误org.json.JsonException:Value <!DOCTYPE

I have looked at several answered posted here and on Google and am still confused why I am getting this error. The json variable I created reads out I do not have permission. I changed the permissions to allow all and this did not solve the error. I also played around with my URL using my computers IP address of 196.... and the online examples of 127.0.0.1. When I use my IP I get the above error. When I used the 127.0 I get failed to connect error, which I assume is because the IP address does not go anywhere. I tested my PHP code and it input data into MySQL db. So I know that my problem is in my java code. I am posting my code below and trying to post minimal code so I do code dump. If you want me to post more code let me know.

        try {

        // check for request method
        if(method.equals("POST")){
            // request method is POST
            // 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();


        }else if(method.equals("GET")){
            // request method is GET
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String paramString = URLEncodedUtils.format(params, "utf-8");
            url += "?" + paramString;
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            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, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "
");
        }
        is.close();
        json = sb.toString();
    } 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;

So what do I need to do to get permission?
The Error message I am getting for

catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

is:

Error parsing data org.json.JSONException: Value DOCTYPE of type java.lang.String cannot be converted to JSONObject
  • 写回答

1条回答 默认 最新

  • douzhong6480 2014-02-17 21:00
    关注

    127.0.0.1 will be your local android device where it's not likely you have a web server running. The permission you need in your manifest is INTERNET, make sure you have it and then update your question to post the exact error and error codes you get if you are still experiencing issues

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!