-2

I have a json as shown below -

   "thothTest":{
      "9876":[
         "K"
      ],
      "5431":[
         "A",
         "L"
      ],
      "5123":[
         "L"
      ]
   }

This is how I get thothTest value. Now I am trying to print each key and their values by iterating json array. Like I want to print 9876 and its whole array by iterating it over them. Similarly for other entries.

var parsedthothTests = parsed["thothTest"];
foreach (var parsedthothTest in parsedthothTests)
{
    Console.WriteLine(parsedthothTest); // this prints innermost array one by one
    foreach (var val in parsedthothTest.Values)
    {

    }
}

In my innermost foreach loop it gives me error as - Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'? What is wrong I am doing here?

David Todd
  • 63
  • 5
  • When posting snippets of code, it helps to not use `var` unless the type is obvious - `var i = 0` is fine, `var x = arr[y]` it is impossible to know what `x` is, and the errors in this question relate to the type of `x`. – DaveShaw Oct 05 '20 at 16:04

1 Answers1

0

I think .Values is a method, not a property.

You should add parenthesis to invoke it.

foreach (var val in parsedthothTest.Values())
{
}
DaveShaw
  • 52,123
  • 16
  • 112
  • 141
  • Aah I got it now. Also how can I get the value of the `key` like 9876. That foreach will iterate array and give access to each value in that array. – David Todd Oct 05 '20 at 16:06
  • Probably best to ask a new question and post a [mvce](https://stackoverflow.com/help/minimal-reproducible-example), someone will be able to run it and figure it out, without knowing the types involved it is hard to say. – DaveShaw Oct 05 '20 at 16:11
  • Its a Jtoken. I just debugged it. – David Todd Oct 05 '20 at 16:12