Okay so I have looked all over and could not find an answer to how to do this.
Here is my json file
{
"item": {
"icon": "icon.png",
"icon_large": "icon_large.png",
"id": 453,
"type": "misc",
"typeIcon": "icontype.png",
"name": "Item name",
"description": "item description",
"current": {
"trend": "neutral",
"price": 174
},
"today": {
"trend": "positive",
"price": "+2"
},
"premium": "false"
}
}
I have tried this class as a way to deserialize it (I only need the item's name and price from the "current" tree)
public class MyItem
{
public Dictionary<string, Item> item;
}
public class Item
{
public string name;
public Dictionary<string, Current> current;
}
public class Current
{
public string price;
}
And this is being called from my main class
private void buttonAddItemToWatcher_Click(object sender, EventArgs e)
{
string url = "link to json above;
string json = new WebClient().DownloadString(url);
MyItem newItem = new MyItem();
JsonConvert.PopulateObject(json, newItem);
}
but I get this error
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' >occurred in Newtonsoft.Json.dll
Additional information: Error converting value >"icon.png" to type 'RS_GrandExchangeWatcher.Item'. Path 'item.icon', line 1, position 95.
I am not quite understanding how I should set up my class in order to populate my MyItem class with the json I have provided