I have a Json file in the following format:
"Adorable Kitten": {"layout": "normal","name": "Adorable Kitten","manaCost": "{W}","cmc": 1,"colors": ["White"],"type": "Host Creature — Cat","types": ["Host","Creature"],"subtypes": ["Cat"],"text": "When this creature enters the battlefield, roll a six-sided die. You gain life equal to the result.","power": "1","toughness": "1","imageName": "adorable kitten","colorIdentity": ["W"]}
and I am using the following code to put it into a list:
using (StreamReader r = new StreamReader(filepath))
{
string json = r.ReadToEnd();
List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);
textBox1.Text = items[0].name.ToString();
}
public class Item
{
public string layout;
public string name;
public string manaCost;
public string cmc;
public string[] colors;
public string type;
public string[] types;
public string[] subtypes;
public string text;
public string power;
public string toughness;
public string imageName;
public string[] colorIdentity;
}
Visual Studio is telling me that the "Adorable Kitten" part of the Json can not be deserialized. Normally I would get rid of that portion of the code but it is an excerpt from a file that is nearly 40000 lines long, so removing that for each item would be impractical. Additionally when i removed "Adorable Kitten" while troubleshooting I got a similar error for "layout". The error says that i need to either put it into a Json array or change the deserialized Type so that it is a normal .Net Type. Can anyone point what I'm doing wrong?