0

I'm trying to parse some JSON, but I'm running into a problem. I'm trying to get the name of the item. JSON: http://steamcommunity.com/id/xejuicy/inventory/json/730/2/

Code I tried:

WebClient wc = new WebClient();
string theItems = wc.DownloadString(string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/730/2/", steamUser.SteamID.ConvertToUInt64()));
dynamic dynObj = JsonConvert.DeserializeObject(theItems);
Console.WriteLine("{0}", dynObj.rgDescriptions,dynObj);
foreach (var name in dynObj)
{
    foreach (var subname in name)
    {
        Console.WriteLine("{0}", subname.name);
    }
}

If you are familiar with CS:GO, i want to get all CS:GO items from steam (even crates), everything from that game I have in inventory and get its name.

Error: JValue doesn't contain definition for name. Where it occurs: second foreach (Console.WriteLine("{0}", subname.name);)

It's not duplicate because i successfully deserialized JSON and can take value but CAN'T get subvalue... Question already answered though.

XeJuicY
  • 51
  • 8

1 Answers1

1
dynamic dynObj = JsonConvert.DeserializeObject(theItems);
foreach (var desc in dynObj.rgDescriptions)
{
    Console.WriteLine("{0} => {1}", desc.Name, desc.Value.name);
}
Eser
  • 12,346
  • 1
  • 22
  • 32