JSON for C # classes - unknown property names

let's say I have the following JSON payload;

  {
   "pagemap": {
    "metatags": [
     {
      "msapplication-task": "name\u003dAbout Tugberk Ugurlu;action-uri\u003d/about;icon-uri\u003d/content/App_Icons/icos/about.ico",
      "msapplication-task": "name\u003dContact;action-uri\u003d/contact;icon-uri\u003d/content/App_Icons/icos/contact.ico",
      "msapplication-task": "name\u003dBlog RSS Feed;action-uri\u003dhttp://feeds.feedburner.com/TugberkUgurlu;icon-uri\u003d/content/App_Icons/icos/rss.ico",
      "msapplication-task": "name\u003dTugberk on Twitter;action-uri\u003dhttp://twitter.com/tourismgeek;icon-uri\u003d/content/App_Icons/icos/twitter.ico",
      "msapplication-starturl": "./",
      "application-name": "Tugberk Blog",
      "msapplication-tooltip": "bla bla bla..."
     }
    ]
   }
  }

Property names in mettags are dynamic. I mean, one of them for this request msapplication-starturl, but maybe msapplication-foofor the other.

So what would be the best C # classes for this JSON payload?

EDIT

this is part of the JSON format that the google search API provides. I also use Json.NET. Is there any other way than dynamic?

+5
source share
2 answers

, MetaTags Dictionary<string,string> List<string>, , msapplication-task , .

: , OP ,

public class PageMap
{
    public Dictionary<string,string> MetaTags {get;set; }
}

json- , RestSharp .

var client = new RestClient("somegoogle.com");
var request = new RestRequest("Some/Foo/Bar", Method.GET)
                                 { RequestFormat = DataFormat.Json }; 
request.AddParameter("p1", "quigybo");
client.Execute<PageMan>(request)
+2

JSON.NE T JObject . , NuGet .

:

var client = new WebClient();
client.Headers.Add("User-Agent", "your user agent here");
var response = client.DownloadString(new Uri("http://www.domain.com/source-page.html"));
JObject jo = JObject.Parse(response);
+2

All Articles