我從URL獲取json但在解析時出錯。這是說非法的性格。你們能指出罪魁禍首嗎? mycode的Json在Android中從URL解析
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 source http://5.39.219.67/~tvinfo/tvguide/box/getprogramlist?mediagroupId=9c476522-d771-4fcd-ae21-34b302c04e46&dateBegin=2013-04-08%2000:00:00&dateEnd=2013-04- 08%2023:00:00&channelList = RTL – 2013-04-08 11:47:03
json不是vaild。 – rajeshwaran 2013-04-08 11:50:01
在這裏檢查,http://jsonformatter.curiousconcept.com/#jsonformatter – rajeshwaran 2013-04-08 11:50:39