2013-03-12 41 views
-3

如何解析以下结果是从https://graph.facebook.com/google/Newtonsoft JSON分析器

 
{ 
    "about": "Organizing the world's information and making it universally accessible and useful.", 
    "checkins": 22645, 
    "company_overview": "Google is a public and profitable company focused on search services. Named for the mathematical term \"googol,\" Google operates web sites at many international domains, with the most trafficked being www.google.com. Google is widely recognized as the \"world's best search engine\" because it is fast, accurate and easy to use. The company also serves corporate clients, including advertisers, content publishers and site managers with cost-effective advertising and a wide range of revenue generating search services. Google's breakthrough technology and continued innovation serve the company's mission of \"organizing the world's information and making it universally accessible and useful.\"", 
    "founded": "1998", 
    "is_published": true, 
    "location": { 
     "street": "1600 Amphitheatre Parkway", 
     "city": "Mountain View", 
     "state": "CA", 
     "country": "United States", 
     "zip": "94043", 
     "latitude": 37.421956357856, 
     "longitude": -122.08422985089 
    }, 
    "mission": "Google's mission is to organize the world's information and make it universally accessible and useful.", 
    "products": "See a full list:\nhttp://www.google.com/options/index.html", 
    "talking_about_count": 60684, 
    "username": "Google", 
    "website": "www.google.com", 
    "were_here_count": 0, 
    "category": "Website", 
    "id": "104958162837", 
    "name": "Google", 
    "link": "http://www.facebook.com/Google", 
    "likes": 12341682, 
    "cover": { 
     "cover_id": "10151163547067838", 
     "source": "http://sphotos-d.ak.fbcdn.net/hphotos-ak-ash3/s720x720/546101_10151163547067838_18950259_n.jpg", 
     "offset_y": 0, 
     "offset_x": 0 
    } 
} 

+0

那你试试? – 2013-03-12 05:08:11

+0

@BhushanFirake:Bhushanji mi sangato na,kahi prayatna kela nahiye tyani。 – Freelancer 2013-03-12 05:09:39

+0

@Freelancer Lolz ......第一次发表Marathi评论.... :) – 2013-03-12 05:11:55

回答

1

不是创建和支持代表JSON结构多类的,我更喜欢反序列化JSON转换成动态对象:

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

粘贴过来的是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); 

您应该看到documentation for Json.Net

+0

谢谢这对我有用。 – VKR 2013-03-12 05:28:03

+0

@ user2159438,不客气 – Habib 2013-03-12 05:29:34