LINQ to JSON: how to get the right format?
im trying to convert my result from a linq query to json using json.net
here is what i did:
JObject o = JObject.FromObject(new
{
UserID = from u in model.USER
select new
{
UserID = u.UserID
}
});
here is what i get:
JSON
id=1
result={"UserID":[{"UserID":121}开发者_开发知识库,"UserID":121},{"UserID":122},{"UserID":123},{"UserID":124}]}
here is what i need:
JSON
id=1
result={[{UserID:'121'},{UserID:'121'},{UserID:'122'},{UserID:'123'},{UserID:'124'}]}
how do i get this done? thank you
Try this:
JArray a = JArray.FromObject(
from u in model.USER
select new
{
UserID = u.UserID
}
);
精彩评论