2014-07-20 37 views
0

我要分析此JSON與Android

["user": { "ver": "1.5", "name": "Cupcake", "api": "API level 3" },"user": { "ver": "1.6", "name": "Donut", "api": "API level 4" },"user": { "ver": "2.0-2.1", "name": "Eclair", "api": "API level 5-7" }] 

與此代碼

private void load() { 
    if (loading != null && !loading.isDone() && !loading.isCancelled()) { 
     return; 
    } 
    String url="http://www.ribony.com/json.php"; 
    loading=Ion.with(this,url) 
      .asJsonArray() 
      .setCallback(new FutureCallback<JsonArray>() { 
       public void onCompleted(Exception e,JsonArray result) { 
        if (e != null) { 
         Log.w("HATA","YUKLEME HATASI"); 
         Log.w("DETAY",e); 
        } 
        for (int i=0; i<result.size(); i++) { 
         Log.w("ADAPTOR","OK"); 
         tweetAdapter.add(result.get(i).getAsJsonObject()); 
        } 
       } 
      }); 
} 

當我嘗試運行這個程序離子解析JSON,應用程序是crashing.Here是我的logcat:http://prntscr.com/44jhdf

我該如何解決?

+0

它是無效的JSON。 '第2行解析錯誤: [「user」:{「ver」:「 -----------^ 期待'}',',',']' – Aniruddha

+0

@Aniruddha Can你給這樣一個例子json?我看不到錯誤在哪裏 –

+0

利用jsonlint.com你會知道錯誤在哪裏 – Aniruddha

回答

1

的錯誤是你的JSON,正確的JSON的樣子:

[ 
    { 
    "user": { 
     "ver": "1.5", 
     "name": "Cupcake", 
     "api": "API level 3" 
    } 
    }, 
    { 
    "user": { 
     "ver": "1.6", 
     "name": "Donut", 
     "api": "API level 4" 
    } 
    }, 
    { 
    "user": { 
     "ver": "2.0-2.1", 
     "name": "Eclair", 
     "api": "API level 5-7" 
    } 
    } 
] 

要verifiy如果你的JSON是正確的,你可以使用http://jsoneditoronline.org/index.html

+0

非常感謝。 –