Chris
Chris

Reputation: 31

JSON Object Help

{
  "accuracy": 0.17,
  "dogr": 108,
  "dogt": 22,
  "elo0": 602.29,
  "elo1": 587.28,
  "games": 305
}

I have those values above from JSON Object,

    JObject general = (JObject)bfbc_array[0]["general"];
    foreach (float generalsNumbers in general.PropertyValues())
    {
        listBox7.Items.Add(generalsNumbers);
    }

That loop iterates through the object and I can retrieve the number of each one. Which is perfect, however I want to retrieve the text as well and I'm completely stumped. What do I need to use so that I can get the text as well? (I am using JSON.NET)

Upvotes: 3

Views: 750

Answers (1)

Ahmad Mageed
Ahmad Mageed

Reputation: 96477

You should be able to loop over general as follows:

JObject general = (JObject)bfbc_array[0]["general"];
foreach (var item in general)
{
    Console.WriteLine("{0} : {1}", item.Key, item.Value);
}

If you need the numbers to be of type float you can cast them:

float value = (float)item.Value;

Upvotes: 3

Related Questions