我有一个看起来像这样的对象模型:
public MyObjectInJson
{
public long ObjectID {get;set;}
public string ObjectInJson {get;set;}
}
该属性ObjectInJson
是一个已序列化的版本,其中包含嵌套列表的对象。目前,我正在MyObjectInJson
像这样手动序列化列表:
StringBuilder TheListBuilder = new StringBuilder();
TheListBuilder.Append("[");
int TheCounter = 0;
foreach (MyObjectInJson TheObject in TheList)
{
TheCounter++;
TheListBuilder.Append(TheObject.ObjectInJson);
if (TheCounter != TheList.Count())
{
TheListBuilder.Append(",");
}
}
TheListBuilder.Append("]");
return TheListBuilder.ToString();
我想知道是否可以用这种危险代码替换JavascriptSerializer
并获得相同的结果。我该怎么做?
谢谢。
System.Web.Extensions
要使用的引用System.Web.Script.Serialization
:stackoverflow.com/a/18746092/1599699 stackoverflow.com/a/19299695/1599699