Newtonsoft Json Parser

本文关键字:Parser Json Newtonsoft | 更新日期: 2023-09-27 18:03:30

如何解析以下来自https://graph.facebook.com/google/

的结果<>之前{"关于":"组织世界上的信息,使其普遍可用和有用。"签到":22645年,"company_overview":"谷歌是一家专注于搜索服务的上市盈利公司。谷歌以数学术语"googol"命名,在许多国际域名上运营网站,访问量最大的是www.google.com。谷歌被广泛认为是"世界上最好的搜索引擎",因为它快速、准确、易于使用。该公司还为企业客户提供服务,包括广告商、内容出版商和网站管理人员,提供具有成本效益的广告和广泛的创收搜索服务。谷歌的突破性技术和持续创新服务于公司的使命,即"组织世界上的信息,使其普遍可访问和有用"。"成立":"1998","is_published":没错,"位置":{"街道":"圆形剧场公园路1600号";"city": "Mountain View";"状态":"CA","国家":"美国";"zip":"94043","人肉搜索":37.421956357856,经度:-122.08422985089},"使命":"谷歌的使命是组织世界上的信息,使其普遍可用和有用。"products": "查看完整列表:'nhttp://www.google.com/options/index.html","talking_about_count":60684年,"用户名":"谷歌","网站":"www.google.com","were_here_count":0,"类别":"网站","id":"104958162837","名称":"谷歌","链接":"http://www.facebook.com/Google","喜欢":12341682,"覆盖":{"cover_id":"10151163547067838","源":"http://sphotos-d.ak.fbcdn.net/hphotos-ak-ash3/s720x720/546101_10151163547067838_18950259_n.jpg","offset_y":0,"offset_x":0}}

Newtonsoft Json Parser

将JSON粘贴到http://json2csharp.com中,它将为您提供映射的类,即:

public class Location
{
    public string street { get; set; }
    public string city { get; set; }
    public string state { get; set; }
    public string country { get; set; }
    public string zip { get; set; }
    public double latitude { get; set; }
    public double longitude { get; set; }
}
public class Cover
{
    public string cover_id { get; set; }
    public string source { get; set; }
    public int offset_y { get; set; }
    public int offset_x { get; set; }
}
public class RootObject
{
    public string about { get; set; }
    public int checkins { get; set; }
    public string company_overview { get; set; }
    public string founded { get; set; }
    public bool is_published { get; set; }
    public Location location { get; set; }
    public string mission { get; set; }
    public string products { get; set; }
    public int talking_about_count { get; set; }
    public string username { get; set; }
    public string website { get; set; }
    public int were_here_count { get; set; }
    public string category { get; set; }
    public string id { get; set; }
    public string name { get; set; }
    public string link { get; set; }
    public int likes { get; set; }
    public Cover cover { get; set; }
}

以后你可以使用Newtonsoft JSON解析器:

RootObject myObject =  JsonConvert.DeserializeObject<RootObject>(jsonString);

您应该看到Json文档。净

比起创建和支持多个表示json结构的类,我更喜欢将json反序列化为动态对象:

dynamic d = JObject.Parse(json);
//d.founded == "1998"