开发者

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
                }
    );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜