【发布时间】:2013-12-27 14:24:39
【问题描述】:
我正在使用 JavascriptSerializer 将列表转换为字符串,但它无法正常工作并且它会抛出 Recursion Limit Exceeded 的错误。我进行了很多搜索,但没有找到解决此问题的任何解决方案。
我的转化如下
List<CustomType> _customValues= serializer.ConvertToType<List<CustomType>>(dictionary["CustomValues"]);
string CustomString = new JavaScriptSerializer().Serialize(_customValues);
编辑
我的自定义类型在下面
public class CustomType
{
private string _name;
public string Name
{
get
{ return _name; }
set
{
if (this._name != value)
{
this._name= value;
}
}
}
private double _mark;
public double Mark
{
get
{ return _mark; }
set
{
if (this._mark!= value)
{
this._mark= value;
}
}
}
private int _id;
public int Id
{
get
{ return _id; }
set
{
if (this._id!= value)
{
this._id= value;
}
}
}
}
如何将该列表转换为字符串? 我该如何克服这个问题?。
谢谢,
卡提克
【问题讨论】:
-
请发布您的 CustomType 课程
-
@BrianDishaw,我已经更新了我的 customType。
-
您的方法的其余部分在进行序列化时是什么样的?
-
您是否在配置文件中设置了 jsonSerialization 元素?检查该元素的对象级别。它可能设置为 1 或 2 之类的低值?
-
基于一些假设,我能够毫无问题地运行与您的代码类似的东西。这让我相信
serializer.ConvertToType<List<CustomType>>(dictionary["CustomValues"])的结果没有返回您所期望的,或者您在课堂上以某种方式包含了非简单类型(例如 Guid) - 但如果没有更多信息,我无法确定。
标签: c# wpf javascriptserializer