0

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.

1
  • 1
    JSONArray internally uses an ArrayList so it's just like wrapper over ArrayList. I would say that there is no significant difference between ArrayList and JSONArray. JSONObject uses HashMap internally. As for Collections, LinkedListis the fastest, by which the most efficient way would be to use LinkedList with JSONObject instead of JSONArrays. Commented Jul 2, 2022 at 9:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.