0

I have this function for returning users and user count

List<User> entitiesList = DB.Users.OrderBy(x => x.UserName).ToList();
var count = DB.Users.Count
return (entitiesList, count)

The result from HTTP request is this

{
    "item1":
[
    {
        "fullName":"Joe Smith"
    },
    {"fullName":"Bob Rogan"
    }
]
    "item2":["2"]
}

Question is why does JSON result has objects named item1 and item2, where does these names come from, I haven't specified such names anywhere, shouldn't there just be no name in such case? And how do I rename 'item1' to 'users' and 'item2' to 'count'?

1 Answer 1

1

It's because you return a tuple, in your case (Class User, integer). You should return a custom class:

public class Response {
    public List<User> Users;
    public int Count;
}

....

return (new Response { Users = entitiesList, Count = count}); 
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.