【发布时间】:2016-01-27 04:04:41
【问题描述】:
我正在使用下一个代码:
dynamic jsonObj = JsonConvert.DeserializeObject(reader.ReadToEnd());
foreach (var item in jsonObj)
{
Console.WriteLine("");
}
reader.ReadToEnd() 有一个 json 字符串。
但是我在 foreach 上有一个错误,
错误 13 foreach 语句不能对类型变量进行操作 'System.Collections.IEnumerable' 因为 'System.Collections.IEnumerable' 不包含公共定义 为了 'GetEnumerator' C:\Users\myUser\Desktop\app\appRecept\Paises.cs 47 29 appPreregistro
【问题讨论】:
-
你的 json 结构是什么样的?它看起来像观察窗口中的数组还是列表?
-
我的 json 看起来像这样: { "success" : "true", "states" : [ { "id" : "1000", "name" : "AGUASCALIENTES", }, { "id " : "1001", "name" : "BAJA CALIFORNIA", }, { "id" : "1002", "name" : "BAJA CALIFORNIA SUR", }, { "id" : "1004", "name" : "ZACATECAS", } ] }