【问题标题】:Json.NET Serializing Run throws StackOverflowExceptionJson.NET 序列化运行抛出 StackOverflowException
【发布时间】:2015-01-21 04:18:20
【问题描述】:

我正在尝试序列化 System.Windows.Documents.Run 对象,并且 JsonConvert.SerializeObject() 会引发 StackOverflowException,即使 ReferenceLoopHandling 设置为 Ignore。为了序列化 Run 对象,我该怎么做?

触发线:

字符串测试 = JsonConvert.SerializeObject(new Run("testing"), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });

【问题讨论】:

    标签: c# json.net stack-overflow


    【解决方案1】:
    try
    {
    var _run = new Run()
    }
    catch (Exception ex)
    {
    //serialize your erorr
    }
    finally
    {
    //impossible but still
    if (_run != null)
    {
    //serialize _run
    }
    }
    

    如果你的对象创建失败,你不能序列化空对象。

    【讨论】:

    • 我不确定你的意思。你是说我的 Run 是空的吗?
    • 对象创建失败(新)-> 构造时抛出错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多