在ASP.NET Web API响应中使用数据作为列表或数组
当我从ASP.NET Web API中的数据库中接收数据时,如果期望收到多个条目,我通常会以列表的形式称呼它们。因此,这很好,因为LINQ为列表提供了一些很酷的方法。
但是我的问题是,我已经看到一些开发人员将API控制器设置为将响应发送给客户端作为列表。我想知道在向客户端发送JSON响应时,是否有任何特殊原因不使用数组,因为显然,JSON字符串从数组或列表序列化之间没有区别。
先感谢您。
When I receive data from a database in my ASP.NET Web API, I generally call them in form of a List if expect to receive multiple entries. So this is fine because LINQ provides some cool methods for work with Lists.
But my question is, I have seen some developers set the API controller to send the response to the client as List. I'm wondering is there any special reason not to use Arrays when sending JSON response to the client because, apparently there is no difference between JSON strings that serialized from Arrays or Lists.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您观察到的那样,在JSON中返回API的数组或列表之间没有区别。因此,只需返回数据所在的表单即可。
As you observed, there is no difference between returning an array or a list from the API, in JSON both will end up as an array. So just return the form that your data is in.