dsa88886666 2014-02-17 12:25
浏览 257
已采纳

继续解析数据的错误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 13: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部