我从URL获取json,但解析时出错。这是在说非法字符。你们能指出罪魁祸首在哪里吗?
我的密码
public String GetJString(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(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();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
Log.d("cstch",json);
return json;
}
错误信息
04-08 15:26:43.393: E/AndroidRuntime(1122): FATAL EXCEPTION: AsyncTask #2
04-08 15:26:43.393: E/AndroidRuntime(1122): java.lang.RuntimeException: An error occured while executing doInBackground()
04-08 15:26:43.393: E/AndroidRuntime(1122): at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-08 15:26:43.393: E/AndroidRuntime(1122): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.lang.Thread.run(Thread.java:856)
04-08 15:26:43.393: E/AndroidRuntime(1122): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 124: http://smkamran.com/~tvinfo/tvguide/box/getprogramlist?mediagroupId=9c476522-d771-4fcd-ae21-34b302c04e46&dateBegin=2013-04-08 00:00:00&dateEnd=2013-04-08 23:59:00&channelList=RBB
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.net.URI.create(URI.java:727)
04-08 15:26:43.393: E/AndroidRuntime(1122): at org.apache.http.client.methods.HttpPost.<init>(HttpPost.java:79)
04-08 15:26:43.393: E/AndroidRuntime(1122): at com.smkamran.germantv.JSONParser.GetJString(JSONParser.java:80)
04-08 15:26:43.393: E/AndroidRuntime(1122): at com.smkamran.germantv.ChannelDetails$GetDataFromServer.doInBackground(ChannelDetails.java:267)
04-08 15:26:43.393: E/AndroidRuntime(1122): at com.smkamran.germantv.ChannelDetails$GetDataFromServer.doInBackground(ChannelDetails.java:1)
04-08 15:26:43.393: E/AndroidRuntime(1122): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-08 15:26:43.393: E/AndroidRuntime(1122): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
最佳答案
您的JSON无效。
出现以下错误
错误:第1行解析错误:
... 1658“,”说明“:”((1658)Simones Wide
----------------------- ^
期望'STRING','NUMBER','NULL','TRUE','FALSE','{','[',得到'undefined'
此时缺少一些括号。
1658“,”说明“:”(1658)
Simones Widerstand乔治(David br \ u00f6ckelt)。