Click here to Skip to main content
15,903,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got stuck here ,please help me out

What I have tried:

i got "[{"name":"Pune","placeType":{"code":7,"name":"Town"},"url":"http:\/\/where.yahooapis.com\/v1\/place\/2295412","parentid":23424848,"country":"India","woeid":2295412,"countryCode":"IN"}]" data from twitter api.
now i have created cs class for the same,so how do i assign this data dynamically to my class fields ?

<pre>dynamic serobj = JsonConvert.SerializeObject(obj);
            var objs = JsonConvert.DeserializeObject<Trendingcloset>(serobj);

public string name { get; set; }
      public string placeType { get; set; }
      public int code { get; set; }
      public string placename { get; set; }
      public string url { get; set; }
      public int parentid { get; set; }
      public string country { get; set; }
      public int woeid { get; set; }
      public string countryCode { get; set; }
Posted
Updated 19-Sep-17 21:38pm

The [ at the start of the json indicates an array so try to deserialize into a List of your object :
C#
var objs = JsonConvert.DeserializeObject<List<Trendingcloset>>(serobj);
 
Share this answer
 
This article covers JSON in detail. There is also a Twitter example: Working with JSON in C# & VB[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900