Android JSON不在三星gio上解析

Android JSON不在三星gio上解析,android,json,Android,Json,我在运行2.3.6的samsung gio上尝试解析一些JSON时遇到了一个奇怪的异常,我在运行4.0的xperia neo上尝试过它,它工作得很好,我还尝试了不同的JSON,它在两个设备上都能工作,我验证了JSON,它是有效的!我提供代码、json文件和logcat,非常感谢您的帮助 分析器 public static JSONObject getJSONObject(String url) throws ClientProtocolException, IOException, JSONEx

我在运行2.3.6的samsung gio上尝试解析一些JSON时遇到了一个奇怪的异常,我在运行4.0的xperia neo上尝试过它,它工作得很好,我还尝试了不同的JSON,它在两个设备上都能工作,我验证了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"
        }
    ]
}
{
    "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"
        }
    ]
}
不工作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"
        }
    ]
}
{
    "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;
}
logcat

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)
试试这个

response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
String s = EntityUtils.toString(entity, HTTP.UTF_8);
来自


您必须导入apache依赖项。

是否尝试在加载时添加UTF-8?加载时什么?在哪里做呢?我已经有了它,我将发布buildJSONString实现控件来设置`httpost.setHeaderContent-type,application/json;字符集=utf-8;`相反,您的headerdidnt工作:我在buildJSONString方法中设置了编码,logcat打印sting时没有编码问题,我的问题是当我尝试插入新的jsonobject时,jsonobject jObj=新的jsonobject s;对不起,我遇到了一个和你相似的问题。我以为这是解决办法-