如何解析谷歌的地方JSON

如何解析谷歌的地方JSON

本文介绍了如何解析谷歌的地方JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一个试图解析谷歌的地方API的JSON结果。我把它叫做使用http的方法,我在字符串得到了JSON结果返回
我该如何解析呢?我REAS的doc和vistited互联网上的两个博客(一个使用谷歌API库和一个似乎是过时的),并没有帮助我

I an trying to Parse the json results of google places api. I called it using http method and I got the json results back in stringHow can I parse it ? I reas the doc and vistited the two blogs on the internet( one uses google api library and one seems to be outdated) and didnt help me

我使用的是标准的Java的JSONObject和GSON由谷歌,但我无法想出一个好办法来分析它(我打电话寻求地方法)
你有什么建议?
感谢ü

I am using the standard java JSONobject and Gson by google, but i am unable to figure out a good way to parse it (i am calling the search places method)What do you recommend?Thank u

对不起,忘了展现JSON响应:

Hi, sorry for forgetting to show the JSON response:

{
   "html_attributions" : [
      "Listings by \u003ca href=\"http://www.yellowpages.ca/\"\u003eYellowPages.ca\u003c/a\u003e"
   ],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 45.39318670,
               "lng" : -75.68352930
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 45.40102170,
                  "lng" : -75.66752190
               },
               "southwest" : {
                  "lat" : 45.38535060,
                  "lng" : -75.69953670
               }
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "6a3f8ef9aae04c8a23c80ab814e8c75a8b685292",
         "name" : "Old Ottawa South",
         "reference" : "adsadada",
         "types" : [ "neighborhood", "political" ],
         "vicinity" : "Ottawa"
      },
   {
         "geometry" : {
            "location" : {
               "lat" : 45.394630,
               "lng" : -75.6837250
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/movies-71.png",
         "id" : "59519a28667351790456ab80aba982347546b2f6",
         "name" : "Mayfair Theatre",
         "rating" : 4.10,
         "reference" : "dfdsf",
         "types" : [ "movie_theater", "establishment" ],
         "vicinity" : "1074 Bank Street, Ottawa"
      }
  ]
}

我要抢,结果部分(并让说,唯一的结果为简单的第一项)和我所做的是以下内容:

I want to grab the results portion (and lets says the first item of the results only for simplicity)and what i did was the following:

JSONObject jso = new JSONObject(response);
String result = jso.getJSONArray("results").getJSONObject(0).toString();
JsonPlacesResult d = new Gson().fromJson(result, JsonPlacesResult.class);


where JsonPlacesResult is

class JsonPlacesResult{

    private JsonPlaces jsonPlaces;


    public JsonPlaces getJsonPlaces(){return jsonPlaces;}



}
class JsonHtml{
    private String html_attribution;

}
class JsonPlaces{
    private Geometry geo;
    private String icon;
    private String id;
    private String name;
    private String rating;
    private String reference;
    private String types;
    private String vicinity;
}
class Geometry{
    private JsonLocation loc;
}
class JsonLocation{
    private String lat;
    private String lng;
}

我结束了在D空对象?为什么是这样!我做错了什么
谢谢

I am ending up with null object in d??? Why is this! what did I do wrongThanks

推荐答案

您可以从这些链接了解。在这些环节中所示很简单的例子。和POST你从人们更加清晰的答案收到JSON的样本。谢谢你。

You can learn from these links. Very simple example shown in these links. And post sample of JSON that you received for more clear answer from people. Thanks.

HTTP://

这篇关于如何解析谷歌的地方JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 20:37