[英]Json Array - retrieve first record in C#
I am obtaining a JSON array in a dynamic object.我在动态 object 中获得了 JSON 数组。 How can I obtain the first item( equivalent of First for List collection)?
如何获得第一项(相当于 List 集合的 First)? How can I check if Json array is empty
如何检查 Json 数组是否为空
If that's all you want to do with it, and if the underlying object implements IEnumerable
, you could use:如果这就是你想要做的,并且如果底层 object 实现
IEnumerable
,你可以使用:
foreach (dynamic item in array)
{
// Use it here
break;
}
Or use First
explicitly:或明确使用
First
:
dynamic first = Enumerable.First(array);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.