I have a string like the following in C#. I tried with JSON.NET but couldn't figure out how to retrieve the value.
"{[{'Name':'AAA','Age':'22','Job':'PPP'},
{'Name':'BBB','Age':'25','Job':'QQQ'},
{'Name':'CCC','Age':'38','Job':'RRR'}]}";
I would like
foreach (user in users){
Messagebox.show(user.Name,user.Age)
}
Any help will be greatly appreciated.
Here is a code sample:
class Program
{
static void Main(string[] args)
{
var text = @"[{'Name':'AAA','Age':'22','Job':'PPP'},
{'Name':'BBB','Age':'25','Job':'QQQ'},
{'Name':'CCC','Age':'38','Job':'RRR'}]";
dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(text);
for (var i = 0; i < data.Count; i++)
{
dynamic item = data[i];
Console.WriteLine("Name: {0}, Age: {1}", (string)item.Name, (string)item.Age);
}
Console.ReadLine();
}
}
I downloaded Json.Net through NuGet, but otherwise this is a standard .NET 4.0 Console App
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With