简体   繁体   中英

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.

But i have an error on 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

If you're deserializing an array of objects from JSON, something that looks like this:

[
  {blah},
  {blah},
  {blah}
]

then deserialize to a List type:

var jsonObj = JsonConvert.DeserializeObject<List<dynamic>>(reader.ReadToEnd());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM