Reputation: 3
how can i use data from these sample API in a c# script?
This is what i get from the web:
[
{
"id": "Item1",
"valueItem": "100.123456",
},
{
"id": "Item2",
"valueItem": "55.23344",
}
]
I simple need it to be a double like:
public double Item1 = 100.123456;
Hope you can help, thanks in advance
Upvotes: 0
Views: 108
Reputation: 30685
Using Json.net you'd do
public class ItemClass
{
public string id { get; set; }
public double valueItem { get; set; }
}
var objList = JsonConvert.DeserializeObject<List<ItemClass>>(json);
You can use http://json2csharp.com/ to generate your base classes if you need to.
foreach(var item in objList)
{
Console.WriteLine("Item value: " + item.valueItem.ToString());
}
Upvotes: 1