0

我正在开发一个 android 应用程序,该应用程序向 google 地方(详细信息)发出请求并获得一个 json 对象作为回报。这是对象https://developers.google.com/places/documentation/details#PlaceDetailsResponses

`{
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "48",
            "short_name" : "48",
            "types" : [ "street_number" ]
         },
         {
            "long_name" : "Pirrama Road",
            "short_name" : "Pirrama Road",
            "types" : [ "route" ]
         },
         {
            "long_name" : "Pyrmont",
            "short_name" : "Pyrmont",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "NSW",
            "short_name" : "NSW",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "AU",
            "short_name" : "AU",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "2009",
            "short_name" : "2009",
            "types" : [ "postal_code" ]
         }
      ],
      "events" : [
        {
          "event_id" : "9lJ_jK1GfhX",
          "start_time" : 1293865200,
          "summary" : "<p>A visit from author John Doe, who will read from his latest book.</p>
                       <p>A limited number of signed copies will be available.</p>",
          "url" : "http://www.example.com/john_doe_visit.html"
        }
      ], ETC`

如何从该 json 中获取特定详细信息。如果我尝试json.getJSONArray("result")它告诉我 json 不是来自该类型,或者如果我尝试json.getString("results")它说结果没有价值。那么如何提取信息,例如 short_name 等?

提前致谢

4

1 回答 1

0

你应该试试

json.getJSONObject("result");

如何获取短名称

JSONObject json=new JSONObject("json");
            JSONObject result=json.getJSONObject("result");
            JSONArray array=result.getJSONArray("address_components");
            for(int i=0;i<array.length();i++)
            {
                JSONObject obj = array.getJSONObject(i);
                String short_name=obj.getString("short_name");
                System.out.println("Short Name:"+short_name);
            }
于 2013-11-11T14:16:51.467 回答