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.

3
  • Need to add a bunch more info. Like, what is the error? When doesit occur? Commented Sep 8, 2015 at 19:55
  • That first Console.WriteLine call has only one parameter in the format string, but gets 2 parameters... Commented Sep 8, 2015 at 19:59
  • That's not the problem tho. But thanks. Commented Sep 8, 2015 at 20:01

1 Answer 1

1
dynamic dynObj = JsonConvert.DeserializeObject(theItems);
foreach (var desc in dynObj.rgDescriptions)
{
    Console.WriteLine("{0} => {1}", desc.Name, desc.Value.name);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Problem is, that i don't know the .Value, look on JSON... It's numbers of item... like "527635071_0"
@XeJuicY Just try it..It works.....
Oh my, you are my savior @Eser

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.