在android上解析json与ion

时间:2014-07-20 14:56:25

标签: android 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" }]

使用此代码

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());
                    }
                }
            });
}

当我尝试运行此应用时,应用程序崩溃。这是我的logcat:http://prntscr.com/44jhdf

我该如何解决?

1 个答案:

答案 0 :(得分: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"
    }
  }
]

要验证您的json是否正确,您可以使用http://jsoneditoronline.org/index.html