{
"Location": "St Kilda",
"Name": "Movie Plaza theatre",
"Day": ["Sunday","Monday","Tuesday","Wednesday","Tuesday","Friday","Saturday"]
}
I can't deserialize this Json. can anyone help me ?
{
"Location": "St Kilda",
"Name": "Movie Plaza theatre",
"Day": ["Sunday","Monday","Tuesday","Wednesday","Tuesday","Friday","Saturday"]
}
I can't deserialize this Json. can anyone help me ?
Create class of your json as below
public class RootObject
{
public string Location { get; set; }
public string Name { get; set; }
public List<string> Day { get; set; }
}
Then write some code as below to get data from json
JObject json = JObject.Parse(your json string);
RootObject obj = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(json);
Update:
Console.WriteLine(obj.Location);
Console.WriteLine(obj.Name);
foreach (var d in obj.Day)
{
Console.WriteLine(d);
}
I think that you can use the C# dynamic type to make things easier. This technique also makes re-factoring simpler as it does not rely on magic-strings.
1. JsonConvert.DeserializeObject
Use JsonConvert.DeserializeObject<RootObject>(string json);
Create your classes on JSON 2 C#. How it read here
If any fields missing in the JSON data should simply be left NULL.
2. Deserializing JSON with Json.NET You can also read how deserializing JSON with Json.NET
3. JsonConvert.Populate
You can also use JsonConvert.Populate(json,obj);
i.e. json is the json string,obj is the target object
Read more about PopulateObject
Hope this help well.