Android org.json.JSONException:应为';:';之后<;钥匙

Android org.json.JSONException:应为';:';之后<;钥匙,android,httpclient,Android,Httpclient,朋友们。我已经从下载了一个示例JSON解析项目 代码是: // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpPost = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntit

朋友们。我已经从下载了一个示例JSON解析项目

代码是:

// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(url);
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, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
}
is.close();
json = sb.toString(); //json is String variable.
Log.i("String Builder", 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());
}
运行时,它抛出
java.lang.string无法转换为JSONObject
exception。 所以在寻找这个问题的解决方案后,我改变了

     jObj = new JSONObject(json);
这一行是

    jObj = new JSONObject("{" + json + "}");
这一行由给出的说明组成。在此之后,我的logcat显示以下错误

03-28 16:24:23.722: E/JSON Parser(1516): Error parsing data org.json.JSONException: Expected ':' after <!DOCTYPE at character 12 of {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
03-28 16:24:23.722: E/JSON Parser(1516): <HTML dir=ltr><HEAD><TITLE>The page cannot be displayed</TITLE>
03-28 16:24:23.722: E/JSON Parser(1516): <STYLE id=L_defaultr_1>A:link {
03-28 16:24:23.722: E/JSON Parser(1516):    FONT: 8pt/11pt verdana; COLOR: #ff0000
03-28 16:24:23.722: E/JSON Parser(1516): }
03-28 16:24:23.722: E/JSON Parser(1516): A:visited {
03-28 16:24:23.722: E/JSON Parser(1516):    FONT: 8pt/11pt verdana; COLOR: #4e4e4e
03-28 16:24:23.722: E/JSON Parser(1516): }
03-28 16:24:23.722: E/JSON Parser(1516): </STYLE>
03-28 16:24:23.722: E/JSON Parser(1516): <META content=NOINDEX name=ROBOTS>
03-28 16:24:23.722: E/JSON Parser(1516): <META http-equiv=Content-Type content="text-html; charset=UTF-8">
03-28 16:24:23.722: E/JSON Parser(1516): <META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
03-28 16:24:23.722: E/JSON Parser(1516): <BODY bgColor=#ffffff>
03-28 16:24:23.722: E/JSON Parser(1516): <TABLE cellSpacing=5 cellPadding=3 width=410>
03-28 16:24:23.722: E/JSON Parser(1516):   <TBODY>
03-28 16:24:23.722: E/JSON Parser(1516):   <TR>
03-28 16:24:23.722: E/JSON Parser(1516):     <TD vAlign=center align=left width=360>
03-28 16:24:23.722: E/JSON Parser(1516):       <H1 id=L_defaultr_2 style="FONT: 13pt/15pt verdana; COLOR: #000000"><ID id=L_defaultr_3><!--Problem-->The page cannot be displayed
03-28 16:24:23.722: E/JSON Parser(1516): </ID></H1></TD></TR>
03-28 16:24:23.722: E/JSON Parser(1516):   <TR>
03-28 16:24:23.722: E/JSON Parser(1516):     <TD width=400 colSpan=2><FONT id=L_defaultr_4
03-28 16:24:23.722: E/JSON Parser(1516):       style="FONT: 8pt/11pt verdana; COLOR: #000000"><ID id=L_defaultr_5><B>Explanation: </B>There is a problem with the page you are trying to reach and it cannot be displayed.</ID></FONT></TD></TR>
03-28 16:24:23.722: E/JSON Parser(1516):   <TR>
03-28 16:24:23.722: E/JSON Parser(1516):     <TD width=400 colSpan=2><FONT id=L_defaultr_6 
03-28 16:24:23.722: E/JSON Parser(1516):       style="FONT: 8pt/11pt verdana; COLOR: #000000">
03-28 16:24:23.722: E/JSON Parser(1516):       <HR color=#c0c0c0 noShade>
03-28 16:24:23.722: E/JSON Parser(1516):       <P id=L_defaultr_7><B>Try the following:</B></P>
03-28 16:24:23.722: E/JSON Parser(1516):       <UL>
03-28 16:24:23.722: E/JSON Parser(1516):         <LI id=L_defaultr_8><B>Refresh page:</B> Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
03-28 16:24:23.722: E/JSON Parser(1516): <LI id=L_defaultr_9><B>Check spelling:</B> Check that you typed the Web page address correctly. The address may have been mistyped.
03-28 16:24:23.722: E/JSON Parser(1516): <LI id=L_defaultr_10><B>Access from a link:</B> If there is a link to the page you are looking for, try accessing the page from that link.
03-28 16:24:23.722: E/JSON Parser(1516):       </UL>
03-28 16:24:23.722: E/JSON Parser(1516):       <HR color=#c0c0c0 noShade>
03-28 16:24:23.722: E/JSON Parser(1516):       <P id=L_defaultr_11>Technical Information (for support personnel)</P>
03-28 16:24:23.722: E/JSON Parser(1516):       <UL>
03-28 16:24:23.722: E/JSON Parser(1516):         <LI id=L_defaultr_12>Error Code: 403 Forbidden. The ISA Server denied the specified Uniform Resource Locator (URL). (12202)
03-28 16:24:23.722: E/JSON Parser(1516):         </UL></FONT></TD></TR></TBODY></TABLE></BODY></HTML>
03-28 16:24:23.722: E/JSON Parser(1516): }
03-28 16:24:23.722:E/JSON解析器(1516):解析数据org.JSON.JSONException时出错:页面后面应显示“:”
03-28 16:24:23.722:E/JSON解析器(1516):无法显示页面

03-28 16:43:41.903:I/String Builder(1543):你没有得到
JSON
响应,你得到的是
HTML
网页(在LogCat中清晰可见)。因此它无法被解析

(您的url响应为403网页:)

错误代码:403禁止。ISA服务器拒绝了指定的统一 资源定位器(URL)。(12202)


要修复此问题,请使用适当的URL打开并返回JSON数据。

您不会得到
JSON
响应,而是得到
HTML
网页(在LogCat中清晰可见)。因此它无法被解析

(您的url响应为403网页:)

错误代码:403禁止。ISA服务器拒绝了指定的统一 资源定位器(URL)。(12202)


要修复此问题,请使用一个正确的URL,您可以打开该URL并返回JSON数据。

确保您使用了正确的URL来获取web服务。我已经提供了我的URL朋友。检查它。请用以下行发布记录的消息:Log.i(“字符串生成器”,json);您是否尝试在浏览器中打开URL?它是否为您提供了正确有效的JSON?是的,朋友。检查此url:确保您使用正确的url获取web服务。我已向我的url朋友提供。检查它。请用以下行发布记录的消息:Log.i(“字符串生成器”,json);您是否尝试在浏览器中打开URL?它是否为您提供了正确有效的JSON?是的,朋友。检查此url:更改您点击的url。确保它指向一个正确的web服务,该服务返回一个JSON响应。在某个地方,您的URL出现了错误,或者该网站基于您的IP或可能的用户代理阻止了您。更改您点击的URL。确保它指向一个正确的web服务,该服务返回一个JSON响应。在某个地方,您的URL出现了错误,或者网站基于您的IP或可能的用户代理阻止了您。
03-28 16:43:41.903: I/String Builder(1543): <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
03-28 16:43:41.903: I/String Builder(1543): <HTML dir=ltr><HEAD><TITLE>The page cannot be displayed</TITLE>
03-28 16:43:41.903: I/String Builder(1543): <STYLE id=L_defaultr_1>A:link {
03-28 16:43:41.903: I/String Builder(1543):     FONT: 8pt/11pt verdana; COLOR: #ff0000
03-28 16:43:41.903: I/String Builder(1543): }
03-28 16:43:41.903: I/String Builder(1543): A:visited {
03-28 16:43:41.903: I/String Builder(1543):     FONT: 8pt/11pt verdana; COLOR: #4e4e4e
03-28 16:43:41.903: I/String Builder(1543): }
03-28 16:43:41.903: I/String Builder(1543): </STYLE>
03-28 16:43:41.903: I/String Builder(1543): <META content=NOINDEX name=ROBOTS>
03-28 16:43:41.903: I/String Builder(1543): <META http-equiv=Content-Type content="text-html; charset=UTF-8">
03-28 16:43:41.903: I/String Builder(1543): <META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
03-28 16:43:41.903: I/String Builder(1543): <BODY bgColor=#ffffff>
03-28 16:43:41.903: I/String Builder(1543): <TABLE cellSpacing=5 cellPadding=3 width=410>
03-28 16:43:41.903: I/String Builder(1543):   <TBODY>
03-28 16:43:41.903: I/String Builder(1543):   <TR>
03-28 16:43:41.903: I/String Builder(1543):     <TD vAlign=center align=left width=360>
03-28 16:43:41.903: I/String Builder(1543):       <H1 id=L_defaultr_2 style="FONT: 13pt/15pt verdana; COLOR: #000000"><ID id=L_defaultr_3><!--Problem-->The page cannot be displayed
03-28 16:43:41.903: I/String Builder(1543): </ID></H1></TD></TR>
03-28 16:43:41.903: I/String Builder(1543):   <TR>
03-28 16:43:41.903: I/String Builder(1543):     <TD width=400 colSpan=2><FONT id=L_defaultr_4
03-28 16:43:41.903: I/String Builder(1543):       style="FONT: 8pt/11pt verdana; COLOR: #000000"><ID id=L_defaultr_5><B>Explanation: </B>There is a problem with the page you are trying to reach and it cannot be displayed.</ID></FONT></TD></TR>
03-28 16:43:41.903: I/String Builder(1543):   <TR>
03-28 16:43:41.903: I/String Builder(1543):     <TD width=400 colSpan=2><FONT id=L_defaultr_6 
03-28 16:43:41.903: I/String Builder(1543):       style="FONT: 8pt/11pt verdana; COLOR: #000000">
03-28 16:43:41.903: I/String Builder(1543):       <HR color=#c0c0c0 noShade>
03-28 16:43:41.903: I/String Builder(1543):       <P id=L_defaultr_7><B>Try the following:</B></P>
03-28 16:43:41.903: I/String Builder(1543):       <UL>
03-28 16:43:41.903: I/String Builder(1543):         <LI id=L_defaultr_8><B>Refresh page:</B> Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
03-28 16:43:41.903: I/String Builder(1543): <LI id=L_defaultr_9><B>Check spelling:</B> Check that you typed the Web page address correctly. The address may have been mistyped.
03-28 16:43:41.903: I/String Builder(1543): <LI id=L_defaultr_10><B>Access from a link:</B> If there is a link to the page you are looking for, try accessing the page from that link.
03-28 16:43:41.903: I/String Builder(1543):       </UL>
03-28 16:43:41.903: I/String Builder(1543):       <HR color=#c0c0c0 noShade>
03-28 16:43:41.903: I/String Builder(1543):       <P id=L_defaultr_11>Technical Information (for support personnel)</P>
03-28 16:43:41.903: I/String Builder(1543):       <UL>
03-28 16:43:41.903: I/String Builder(1543):         <LI id=L_defaultr_12>Error Code: 403 Forbidden. The ISA Server denied the specified Uniform Resource Locator (URL). (12202)
03-28 16:43:41.903: I/String Builder(1543):         </UL></FONT></TD></TR></TBODY></TABLE></BODY></HTML>