Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 反序列化未知类型的JSON(Google Map API)_C#_Json_Google Maps - Fatal编程技术网

C# 反序列化未知类型的JSON(Google Map API)

C# 反序列化未知类型的JSON(Google Map API),c#,json,google-maps,C#,Json,Google Maps,我正在尝试使用谷歌地图api。此URL正是我需要的: 看看结果。它有我需要的所有信息。。。纬度、纬度、州、国家。问题是,我不知道如何提取这些数据。我试过这个: var client = new WebClient(); var content = client.DownloadString("http://maps.googleapis.com/maps/api/geocode/json?address=77379"); object myObject = JsonConvert.Deseri

我正在尝试使用谷歌地图api。此URL正是我需要的:

看看结果。它有我需要的所有信息。。。纬度、纬度、州、国家。问题是,我不知道如何提取这些数据。我试过这个:

var client = new WebClient();
var content = client.DownloadString("http://maps.googleapis.com/maps/api/geocode/json?address=77379");
object myObject = JsonConvert.DeserializeObject(content);
虽然这不会出错,
myObject
最终没有任何用处。(或者,也许是的,我只是不知道?)


根据我使用JSON的经验,我一直使用这种方法:

object myObject = JsonConvert.DeserializeObject(content);

这样行吗?或者这与你正在做的有什么不同吗?

这是你的班级结构

public class AddressComponent
    {
        public string long_name { get; set; }
        public string short_name { get; set; }
        public List<string> types { get; set; }
    }

public class Northeast
{
    public double lat { get; set; }
    public double lng { get; set; }
}

public class Southwest
{
    public double lat { get; set; }
    public double lng { get; set; }
}

public class Bounds
{
    public Northeast northeast { get; set; }
    public Southwest southwest { get; set; }
}

public class Location
{
    public double lat { get; set; }
    public double lng { get; set; }
}

public class Northeast2
{
    public double lat { get; set; }
    public double lng { get; set; }
}

public class Southwest2
{
    public double lat { get; set; }
    public double lng { get; set; }
}

public class Viewport
{
    public Northeast2 northeast { get; set; }
    public Southwest2 southwest { get; set; }
}

public class Geometry
{
    public Bounds bounds { get; set; }
    public Location location { get; set; }
    public string location_type { get; set; }
    public Viewport viewport { get; set; }
}

public class Result
{
    public List<AddressComponent> address_components { get; set; }
    public string formatted_address { get; set; }
    public Geometry geometry { get; set; }
    public string place_id { get; set; }
    public List<string> postcode_localities { get; set; }
    public List<string> types { get; set; }
}

public class RootObject
{
    public List<Result> results { get; set; }
    public string status { get; set; }
}
公共类地址组件
{
公共字符串长_名称{get;set;}
公共字符串短_名称{get;set;}
公共列表类型{get;set;}
}
公共课东北
{
公共双lat{get;set;}
公共双精度{get;set;}
}
西南公务舱
{
公共双lat{get;set;}
公共双精度{get;set;}
}
公共类界限
{
公共东北{get;set;}
公共西南西南{get;set;}
}
公共类位置
{
公共双lat{get;set;}
公共双精度{get;set;}
}
公共类东北2
{
公共双lat{get;set;}
公共双精度{get;set;}
}
公共课西南2
{
公共双lat{get;set;}
公共双精度{get;set;}
}
公共类视口
{
公共东北2东北{get;set;}
公共西南2西南{get;set;}
}
公共课几何
{
公共边界{get;set;}
公共位置位置{get;set;}
公共字符串位置\u类型{get;set;}
公共视口{get;set;}
}
公开课成绩
{

public List

您是否尝试过创建对象来提取json?OP似乎没有使用json.NET。是的,我是。对不起,我的OP使用了json.NET的包装器。我会试试这个。谢谢!我已经有了这些类,但我试图反序列化到结果,而不是根对象。有时我们会忽略一些小事情。很高兴我能提供帮助!
RootObject rootObject = new JavaScriptSerializer().Deserialize<RootObject>(content);