在 C# 中反序列化 PLINQO 对象的问题

发布于 2024-08-09 14:03:05 字数 828 浏览 2 评论 0原文

我尝试了很多方法来反序列化 LINQO 对象,但每种方法都失败了。这是最后一个代码的示例。

        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SalesNetData.Country));
        string xmlData = Session["CCC"].ToString();
        byte[] byteArray = new byte[xmlData.Length];
        byteArray = encoding.GetBytes(xmlData);

        MemoryStream stream1 = new MemoryStream(byteArray);

        SalesNetData.Country country = (SalesNetData.Country)ser.ReadObject(stream1);
        Console.WriteLine("Deserialized Country data:");

但我现在收到以下错误。

类型“SalesNetData.Country”无法序列化为 JSON,因为其 IsReference 设置为“True”。 JSON 格式不支持引用,因为没有用于表示引用的标准化格式。要启用序列化,请禁用该类型或该类型的适当父类上的 IsReference 设置。

请帮忙......

I have tried many ways to deserialize LINQO objects but every method failed. Here is an example of the last code.

        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SalesNetData.Country));
        string xmlData = Session["CCC"].ToString();
        byte[] byteArray = new byte[xmlData.Length];
        byteArray = encoding.GetBytes(xmlData);

        MemoryStream stream1 = new MemoryStream(byteArray);

        SalesNetData.Country country = (SalesNetData.Country)ser.ReadObject(stream1);
        Console.WriteLine("Deserialized Country data:");

But I get the following error now.

The type 'SalesNetData.Country' cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type.

Please help.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年华零落成诗 2024-08-16 14:03:05

请参阅以下线程 (community.codesmithtools.com/forums/p/10080/37441.aspx#37441) 以获取此问题的解决方案。您还应该考虑使用 Newton Json.NET (codeplex.com/Json)。

谢谢
——布莱克·尼米斯基

Please see the following thread (community.codesmithtools.com/forums/p/10080/37441.aspx#37441) for a solution to this issue. You should also take a look into using Newton Json.NET (codeplex.com/Json).

Thanks
-Blake Niemyjski

风追烟花雨 2024-08-16 14:03:05

解决方案在错误消息中...

要启用序列化,请禁用该类型或该类型的适当父类上的 IsReference 设置

The solution is in the error message...

To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文