首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Json提取并保存到Arraylist Android中

将Json提取并保存到Arraylist Android中
EN

Stack Overflow用户
提问于 2013-12-18 07:21:45
回答 5查看 145关注 0票数 0

如何提取下面的json并将其保存在数组中。

代码语言:javascript
复制
   {
            "trains": {
                "train": [
                    {
                        "@id": 1000000103,
                        "@version": 1,
                        "@status": "active",
                        "@name": "dffffff",
                        "@description": "ffffff half of the nineteenth century.",
                        "@city": "fff",
                        "@phone": "+230 595-1454",
                        "@email": "ffffr@mffc.mu",
                        "@website": "www4u",
                        "@latitude": -5.2882,
                        "@longitude": 3.499,
                        "@defaultLocale": "",
                        "@holes": 48,
                        "@par": 72,
                        "@slope": 0,
                        "@distance": 5.005273,
                        "circuits": {
                            "circuit": []
                        },
                        "localizations": {
                            "localization": []
                        }
                    },
                    {
                        "@id": 1000000105,
                        "@version": 1,
                        "@status": "active",
                        "@name": " xClub",
                        "@description": "",
                        "@city": " xlet",
                        "@phone": "+44465\t",
                        "@email": "",
                        "@website": "wweffl.com",
                        "@latitude": -2.040318,
                        "@longitude": 54548,
                        "@defaultLocale": "",
                        "@holes": 18,
                        "@par": 32,
                        "@slope": 0,
                        "@distance": 2441673,
                        "circuits": {
                            "circuit": []
                        },
                        "localizations": {
                            "localization": []
                        }
                    }
                ]
            }

    }

我的工作

代码语言:javascript
复制
try {

                jobj_trouve_train = new JSONObject(reponse_trouve_train);

                String jsonobj = jobj_trouve_golf.getString("trains");
                //String jsonobj1 = jobj_trouve_golf.getString("train");

                //jobj_trouve_train = new JSONObject(reponse_trouve_train);

                //jsonArray = jobj_trouve_golf.getJSONArray("trains");
                //jsonArray= new JSONArray(jsonobj);

                //System.out.println("jsonArray "+jsonArray);

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-12-18 07:27:07

试试这个..。

代码语言:javascript
复制
try {

                jobj_trouve_train = new JSONObject(reponse_trouve_train);

                JSONObject jsonobj = jobj_trouve_train.getJSONObject("trains");
                JSONArray jsonobj1 = jsonobj.getJSONArray("train");

          for(int i = 0;i< jsonobj1.length();i++){
                JSONObject jsonj = jsonobj1.getJSONObject(i);

                System.out.println("@id "+jsonj.getString("@id"));
                //   Same for remaining all 
                }

            } catch (JSONException e) {
                // TODO Auto-generated catch block                  

                   e.printStackTrace();
        }
票数 2
EN

Stack Overflow用户

发布于 2013-12-18 07:25:03

您可以使用谷歌开发的Gson库将Json解析为objects。参考在这里:https://code.google.com/p/google-gson/,并且,示例示例在这里:JSON Parsing with GSON

票数 0
EN

Stack Overflow用户

发布于 2013-12-18 07:26:43

代码语言:javascript
复制
JSONObject trains = jobj_trouve_train.getJSONObject("trains");
JSONArray trainArray = trains.getJSONArray("train");

JSONObject train1 = trainArray.getJSONObject(0);
...

如果我没有被弄糊涂,也许这张是对的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20651919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档