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 把Excel导入MATLAB显示错误怎么解决?
  • ¥15 Java中消息和缓存如何使用
  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx