2012-03-30 23 views
1

これは突然、次のコードはうまくいきません。 Webページは、すでにかなりよく示してどのような私のAndroidの表示をしようと:それは私の配列が実際になかった場合には多くの意味になるだろう、次のメッセージ、とJSONArrayの作成時にクラッシュしJSONArrayのテキストは、[...]の文字で始まる必要があります。これは完璧ですが、 '['で始まります。

HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost; 
      httppost = new HttpPost(myUrl);    
      try 
      {     
       HttpResponse response = httpclient.execute(httppost); 
       StringBuilder strResponse = inputStreamToString(response.getEntity().getContent()); 
       JSONArray arrWishlists = new JSONArray(strResponse.toString()); 
       .... 
       the rest is not important 

私はここのAndroidからアクセスしようとしている同じページ上のJavaScriptで使用された場合、完全に動作し、本当に法的なJSON配列:

03-30 02:55:21.304: W/System.err(346): org.json.JSONException: A JSONArray text must start with '[' at character 1 of [{"Index":"296","Name":"\u041c\u0410\u0428\u0418\u041d\u042b","Description":"","VisibleToFriends":"1","Items":[{"Name":"porche 911","Description":"","Image":"http:\/\/www.tuningnews.net\/wallpaper\/1024x768\/porsche-911-carrera-s-coupe-01.jpg","Index":"0","Link":"http:\/\/www.autotrader.com\/research\/car-models\/2012-Porsche-911\/21675-336697-Coupe\/2dr-Cpe-S-Turbo~model.jsp","ReservedBy":"1225198689"},{"Name":"Ferrari","Description":"F150","Image":"http:\/\/4.bp.blogspot.com\/-szn3PGyHsC4\/TVPtm1Eh2HI\/AAAAAAAADiI\/58R4x_IaE9g\/s1600\/ferrari_f150_1680_8.jpg","Index":1,"Link":"http:\/\/en.wikipedia.org\/wiki\/Ferrari_150\u00b0_Italia","ReservedBy":"1374872217"},{"Name":"Lamborgini","Description":"Diablo","Image":"http:\/\/users1.ml.mindenkilapja.hu\/users\/ozdsuli\/uploads\/lamborgini.jpg","Index":2,"Link":"","ReservedBy":"1225198689"}]},{"Index":"341","Name":"Birthday","Description":"My birthday wishes","VisibleToFriends":"1","Items":[{"Name":"iPad 3 ","Description":"Need for speed","Image":"http:\/\/www.techieday.com\/wp-content\/uploads\/2011\/05\/ipad-3-release-date.jpg","Index":"0","Link":"","ReservedBy":"1225198689"},{"Name":"iOS Development License","Description":"100$","Image":"http:\/\/www.geek.com\/wp-content\/uploads\/2010\/09\/apps_20100901.jpg","Index":1,"Link":"http:\/\/developer.apple.com\/programs\/ios\/","ReservedBy":""}]}] 

答えて

0

は、私はあなたがinputStreamToStringに何をしているかわからないが、この

をやってみてください
private String convertToString(InputStream istr){ 
    if(istr == null){ 
     return ""; 
    } 
    try { 
     return new java.util.Scanner(istr).useDelimiter("\\A").next(); 
    } catch (java.util.NoSuchElementException e) { 
     return ""; 
    } 
} 

そして、私は基本的に文字列にストリームを変換するのと同じメカニズムを使用してい

String strResponse = convertToString(response.getEntity().getContent()); 
JSONArray arrWishlists = new JSONArray(strResponse); 
+0

あなたのHTTPコードではなく、StringBuilderを持ちます。ちょうどあなたの方法を試してみましたが、うまくいきませんでした。私のコードに関することは、私がホスティングプロバイダを変更するまで完全に機能したことです。私の推測では、新しいものはJSONパーサーを壊すいくつかの異なるエンコーディングでhttp応答を送信するということです... – taralex

関連する問題