开发者

How to serialize IList<object> to string

Having an IList<NameValue> nameValueList, I need to convert that list to string for sending to aspx file开发者_运维知识库 as json. But because this happens in a project that does not have reference to system.web.script or system.web.mvc, i should use another way to serialize the IList

NameValue is an object that have 2 public properties (name and value)


This C# 4 snippet should serialize your collection to a JSON string:

"[" +
string.Join(",",
  from nv in list
  select string.Format("{{ name: {0}, value: {1} }}", nv.Name, nv.Value)
) + 
"]"


What about just using Json.NET (and possibly Linq-to-Json)?

Here's an example of Linq-to-Json

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜