开发者

Android parse this JSON - how? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

my json:

[
    {
        "all": {
            "dates": [
                {
                    "date": "2011-01-18",
                    "name": "asd"
                },
                {
                    "date": "2011-02-19",
                开发者_开发技巧    "name": "ddd"
                },
                {
                    "date": "2011-11-21",
                    "name": "eee"
                }
            ],
            "dep": [
                {
                    "code": "BBB",
                    "name": "BUD"
                }
            ],
            "citys": [
                {
                    "id": "2163",
                    "name": "ASD"
                },
                {
                    "id": "2369",
                    "name": "EFG"
                },

...

my code

                JSONArray json = new JSONArray(s); //json string
                for(int i=0;i<json.length();i++){
                    String settings         = json.getJSONObject(i).getString("all");
                    JSONArray jsonarray     = new JSONArray(settings);

                    for (int j=0; j<jsonarray.length();j++){

                        String dates            = jsonarray.getJSONObject(j).getString("dates");
                        JSONArray jsonarray2    = new JSONArray(dates);

                        for (int k=0; k<jsonarray2.length();k++){
                            String date         =    jsonarray2.getJSONObject(k).getString("date");


                            Log.e("date", date);
                        }
..

.

07-19 09:52:31.356: ERROR/ex(19038): org.json.JSONException: Value {"citys":[{"id":"2163","...

How can I parse this file correctly?

Thanks, Leslie


json.getJSONObject(i).getString("all");
JSONArray jsonarray     = new JSONArray(settings);

'all' is a JSONObject, not a JSONArray, so get JSONObject and get JSONArrays dates,dep,citys.

Can directly get json.getJSONObject(i).getJSONObject("all"); or getJSONObject from String, JSONObject jsonobj = new JSONObject(settings);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜