简体   繁体   English

使用数据作为列表或 ASP.NET Web ZDB974238714CA8DE634A7CE1D083A 中的 Arrays 响应

[英]Using data as Lists or Arrays in ASP.NET Web API response

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.当我从 ASP.NET Web API 中的数据库接收数据时,如果希望收到多个条目,我通常以列表的形式调用它们。 So this is fine because LINQ provides some cool methods for work with Lists.所以这很好,因为 LINQ 提供了一些很酷的方法来处理列表。

But my question is, I have seen some developers set the API controller to send the response to the client as List.但我的问题是,我看到一些开发人员将 API controller 设置为将响应发送给客户端作为列表。 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. 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.先感谢您。

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.正如您所观察到的,从 API 返回数组或列表之间没有区别,在 JSON 中,两者都将以数组形式结束。 So just return the form that your data is in.因此,只需返回您的数据所在的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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