我试图将我的结果从linq查询转换为json 使用json.net
这就是我所做的:
JObject o = JObject.FromObject(new
{
UserID = from u in model.USER
select new
{
UserID = u.UserID
}
});
这是我得到的:
JSON
id=1
result={"UserID":[{"UserID":121},"UserID":121},{"UserID":122},{"UserID":123},{"UserID":124}]}
这就是我需要的:
JSON
id=1
result={[{UserID:'121'},{UserID:'121'},{UserID:'122'},{UserID:'123'},{UserID:'124'}]}
我如何完成这项工作?谢谢
答案 0 :(得分:9)
试试这个:
JArray a = JArray.FromObject(
from u in model.USER
select new
{
UserID = u.UserID
}
);