samsung gio(2.3.6を実行)でJSONを解析しようとすると奇妙な例外が発生しました.xperia neo(4.0を実行)で試してみました.デバイス、私は JSON を検証しましたが、それは有効です! コード、json ファイル、および logcat を提供しています。助けていただければ幸いです。
パーサー
public static JSONObject getJSONObject(String url) throws ClientProtocolException, IOException, JSONException
{
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
HttpResponse response;
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
//buildJSONString( inputStream );
String s = buildJSONString( inputStream );
Log.v("", s); // note that s is printed along all json files and all devices
JSONObject jObj = new JSONObject( s );
Log.v("", jObj +""); // it doesnt print on samsung, prints on xperia
return jObj ;
}
private static String buildJSONString( InputStream inputStream ) throws IOException
{
BufferedReader reader;
StringBuilder stringBuilder=null;
reader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"), 8);
stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
stringBuilder.append(line + "\n");
if (inputStream != null)
inputStream.close();
return stringBuilder.toString();
}
ワーキングjson
{
"song_list": [
{
"id": "4",
"title_en": "Aces High",
"artist_en": "IRON MAIDEN",
"thumb_url": "http://192.168.0.81:8080/content/iron_maiden.jpg",
"media_url": "http://192.168.0.81:8080/content/iron_maiden.mp3",
"preview_url": "blabla",
"num_download": "2846",
"price": "0.50",
"rating" : "4"
},
{
"id": "8",
"title_en": "Wasted Years",
"artist_en": "IRON MAIDEN",
"thumb_url": "http://192.168.0.81:8080/content/iron_maiden.jpg",
"media_url": "http://192.168.0.81:8080/content/iron_maiden.mp3",
"preview_url": "blabla",
"num_download": "1984",
"price": "0.50",
"rating" : "4"
}
]
}
jsonが機能しない
{
"artist_list": [
{
"id": "1",
"artist_en": "MOTORHEAD",
"artist_ar": "موتورهيد",
"thumb_url": "http://192.168.0.81:8080/content/motorhead.jpg",
"num_download": "2846"
},
{
"id": "2",
"artist_en": "WHITESNAKE",
"artist_ar": "وايتسنيك",
"thumb_url": "http://192.168.0.81:8080/content/whitesnake.jpg",
"num_download": "1984"
}
]
}
サーバーヒット
@Override
protected String doInBackground(String... arg0)
{
try
{ jObject = JSONParser.getJSONObject(url); }
catch (Exception e)
{ cancel(true); Log.v("", "failed"); }
return null;
}
ログキャット
09-25 16:04:31.869: V/(10704): ?{
09-25 16:04:31.869: V/(10704): "artist_list": [
09-25 16:04:31.869: V/(10704): {
09-25 16:04:31.869: V/(10704): "id": "1",
09-25 16:04:31.869: V/(10704): "artist_en": "MOTORHEAD",
09-25 16:04:31.869: V/(10704): "artist_ar": "موتورهيد",
09-25 16:04:31.869: V/(10704): "thumb_url": "http://192.168.0.81:8080/content/motorhead.jpg",
09-25 16:04:31.869: V/(10704): "num_download": "2846"
09-25 16:04:31.869: V/(10704): },
09-25 16:04:31.869: V/(10704): {
09-25 16:04:31.869: V/(10704): "id": "2",
09-25 16:04:31.869: V/(10704): "artist_en": "WHITESNAKE",
09-25 16:04:31.869: V/(10704): "artist_ar": "وايتسنيك",
09-25 16:04:31.869: V/(10704): "thumb_url": "http://192.168.0.81:8080/content/whitesnake.jpg",
09-25 16:04:31.869: V/(10704): "num_download": "1984"
09-25 16:04:31.869: V/(10704): }
09-25 16:04:31.869: V/(10704): ]
09-25 16:04:31.869: V/(10704): }
09-25 16:04:31.869: W/AsyncTask(10704): java.lang.InterruptedException
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1272)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:220)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask.get(FutureTask.java:83)
09-25 16:04:31.869: W/AsyncTask(10704): at android.os.AsyncTask$3.done(AsyncTask.java:196)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask$Sync.innerCancel(FutureTask.java:294)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask.cancel(FutureTask.java:76)
09-25 16:04:31.869: W/AsyncTask(10704): at android.os.AsyncTask.cancel(AsyncTask.java:325)
09-25 16:04:31.869: W/AsyncTask(10704): at com.dwaik.jsonparser.ServerHit.doInBackground(ServerHit.java:36)
09-25 16:04:31.869: W/AsyncTask(10704): at com.dwaik.jsonparser.ServerHit.doInBackground(ServerHit.java:1)
09-25 16:04:31.869: W/AsyncTask(10704): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-25 16:04:31.869: W/AsyncTask(10704): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-25 16:04:31.869: W/AsyncTask(10704): at java.lang.Thread.run(Thread.java:1019)