[英]How iterate through json object in c#
im using the next code: 即时通讯使用下面的代码:
dynamic jsonObj = JsonConvert.DeserializeObject(reader.ReadToEnd());
foreach (var item in jsonObj)
{
Console.WriteLine("");
}
Where reader.ReadToEnd()
has a json string. 其中
reader.ReadToEnd()
具有json字符串。
But i have an error on foreach, 但是我在foreach上有一个错误,
Error 13 foreach statement cannot operate on variables of type 'System.Collections.IEnumerable' because 'System.Collections.IEnumerable' does not contain a public definition for 'GetEnumerator' C:\\Users\\myUser\\Desktop\\app\\appRecept\\Paises.cs 47 29 appPreregistro
错误13 foreach语句无法对类型为'System.Collections.IEnumerable'的变量进行操作,因为'System.Collections.IEnumerable'不包含'GetEnumerator'C:\\ Users \\ myUser \\ Desktop \\ app \\ appRecept \\ Paises的公共定义。 CS 47 29应用程序
If you're deserializing an array of objects from JSON, something that looks like this: 如果要从JSON反序列化对象数组,则如下所示:
[
{blah},
{blah},
{blah}
]
then deserialize to a List type: 然后反序列化为List类型:
var jsonObj = JsonConvert.DeserializeObject<List<dynamic>>(reader.ReadToEnd());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.