【问题标题】:Parse JSON without tree [duplicate]解析没有树的 JSON [重复]
【发布时间】:2015-08-17 06:45:57
【问题描述】:

我有一个这样的 JSON。

[
  {"latitude":40.91769,"longtitude":29.18127},
  {"latitude":40.91863,"longtitude":29.18149},
  {"latitude":40.91868,"longtitude":29.18153},
   ///-------///
  {"latitude":40.91423,"longtitude":29.18741},
  {"latitude":40.91471,"longtitude":29.18587}
]

但我没有像树一样的结构。它更像是一个数组。如何一一解析经纬度?

【问题讨论】:

  • 你尝试了什么,什么不适合你?
  • 这需要非常基础的 Json 解析。到目前为止,您尝试过什么吗?请先自行尝试。这有很好的解释答案。 stackoverflow.com/questions/9605913/…
  • 在这里发布你的安卓代码。
  • 我不明白为什么这个问题会成为投票的候选人?我可以看到一个 +1 和一个 -1
  • 请做一些研究。这里不允许用勺子喂食。

标签: android json


【解决方案1】:
    public void parseJson(String json) {
    try {       
            JSONArray root = new JSONArray(json);
            for (int i = 0; i < root.length(); i++) {
                JSONObject att = (JSONObject) root.getJSONObject(i);
                String lat = att.getString("latitude");
                String log = att.getString("longtitude");

            }
       } catch (JSONException e) {
        e.printStackTrace();
      }
    }

【讨论】:

  • 虽然你的答案是正确的,但用勺子喂食是个坏主意。希望你能理解。
  • @Mohit 谢谢它对我有用
猜你喜欢
  • 2019-01-29
  • 2014-03-18
  • 2015-05-18
  • 2017-06-10
  • 2021-10-04
  • 2012-04-10
  • 2016-02-24
  • 2017-01-09
  • 1970-01-01
相关资源
最近更新 更多