我有一个简单的序列化json数组
string json = "[{\"id\":100,\"UserId\":99},{\"id\":101,\"UserId\":98}]";
var data = (List<Model>)Newtonsoft.Json.JsonConvert.DeserializeObject(json , typeof(List<Model>));
我的反序列化模型:
public class Model
{
public int? id { get; set; }
public int? UserId { get; set; }
}
从每个索引中检索数据并将其打印到控制台的最佳方法是什么?
发布于 2016-03-22 06:25:49
string json = "[{\"id\":100,\"UserId\":99},{\"id\":101,\"UserId\":98}]";
var objects = JArray.Parse(json);
var firstIndexValue = objects[0];
Console.WriteLine(firstIndexValue);
foreach (var index in objects)
{
Console.WriteLine(index);
}
for (int index = 0; index < objects.Count; index++)
{
Console.WriteLine(objects[index]);
}
发布于 2016-03-22 06:31:14
您可以执行一个foreach
循环:
foreach(var item in data) {
Console.WriteLine(item.UserId);
}
https://stackoverflow.com/questions/36156468
复制