Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Object Help

Tags:

json

c#

json.net

{
  "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)

like image 732
Chris Avatar asked Apr 23 '26 16:04

Chris


1 Answers

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;
like image 97
Ahmad Mageed Avatar answered Apr 26 '26 05:04

Ahmad Mageed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!