2013-04-08 73 views
1

我從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) 
+0

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

+0

json不是vaild。 – rajeshwaran 2013-04-08 11:50:01

+0

在這裏檢查,http://jsonformatter.curiousconcept.com/#jsonformatter – rajeshwaran 2013-04-08 11:50:39

回答

0

您的JSON無效。

得到以下錯誤

錯誤:在第1行解析錯誤: ... 1658" , 「描述」:「(1658)Simones寬 ------------- ----------^ 期待STRING,NUMBER,NULL,TRUE,FALSE,''在這一點上,括號缺失。

1658「,」description「:」(1658) Simones Widerstand gegen \ David David \ u00f6ckelt。

3

按該錯誤消息,它在查詢字符串部分您的網址非法字符。您應該在該網址上使用URLEncoder.encode()

+0

問題通過添加URLEncoder.encode(URL)解決.. – 2013-04-08 12:03:39