Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Foreach在迭代json数组时无法对“方法组”进行操作?_C#_Json_Json.net - Fatal编程技术网

C# Foreach在迭代json数组时无法对“方法组”进行操作?

C# Foreach在迭代json数组时无法对“方法组”进行操作?,c#,json,json.net,C#,Json,Json.net,我有一个json,如下所示- "thothTest":{ "9876":[ "K" ], "5431":[ "A", "L" ], "5123":[ "L" ] } 这就是我得到测试

我有一个json,如下所示-

   "thothTest":{
      "9876":[
         "K"
      ],
      "5431":[
         "A",
         "L"
      ],
      "5123":[
         "L"
      ]
   }
这就是我得到测试值的方法。现在我试图通过迭代json数组来打印每个键及其值。我想通过对9876及其整个数组进行迭代来打印它。其他条目也是如此

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

    }
}
在我最里面的foreach循环中,它给了我一个错误,因为-foreach不能对“方法组”进行操作。您是否打算调用“方法组”?我在这里怎么了?

我想。值是一种方法,而不是属性

您应该添加括号来调用它

foreach (var val in parsedthothTest.Values())
{
}

当发布代码片段时,除非类型明显,否则不要使用var是有帮助的-var i=0很好,var x=arr[y]不可能知道x是什么,这个问题中的错误与x的类型有关。啊,我现在知道了。还有,我怎样才能得到像9876这样的键的值。foreach将迭代数组并访问该数组中的每个值。可能最好是提出一个新问题并发布一篇文章,有人将能够运行它并找出它,而不知道所涉及的类型,这很难说。这是一个Jtoken。我刚刚调试过。