I would like to convert a list of User's properties into strings array (for json receiver) like:
List<User> users = <..list of users from db...>
var jsonData = (
from user in users
select new { user.Id, user.Person.Lastname, user.Person.Firstname });
return Json(jsonData)
The result is an array named fields
[{"Id":1,"Lastname":"Doe","Firstname":"John"},{"Id":2,"Lastname":"Smith","Firstname":"Adam"},...]
but I would like it to be the array of arrays of plain strings like:
[["1","Doe","John"]
["2","Smith","Adam"], ...]
How to cast linq result to strings array?
var jsonData = from user in users
select new[] { user.Id.ToString(),
user.Person.Lastname,
user.Person.Firstname };
Alternatively, you can use the lambda syntax:
var jsonData = users.Select(user => new[] { user.Id.ToString(),
user.Person.Lastname,
user.Person.Firstname });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With