JSON Serializaion到aaray列表 [英] JSON Serializaion to aaray list

查看:97
本文介绍了JSON Serializaion到aaray列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用



[System.Xml.Serialization.XmlArrayItem(typeof) (DTContractTaxBreakdown))]

属性



Hi,

I am using

[System.Xml.Serialization.XmlArrayItem(typeof(DTContractTaxBreakdown))]
on a property

public ArrayList TaxBreakdown
       {
           get
           {
               return _taxBreakdown;
           }
           set
           {
               _taxBreakdown = value;
           }
       }





它在二进制序列化方面工作得很好,但是在JSON序列化的情况下它无效。



我想在不改变属性类型的情况下将这些对象序列化为JSON。

等于[System.Xml.Serialization.XmlArrayItem(typeof( DTContractTaxBreakdown))
JSON中的


i我使用newtonsoft.json和c#



提前致谢! !!



its working fine in binary serialization but in case of JSON serialization its not working.

I wants to serialize these object into JSON without changing type of property.
Equivqlent of [System.Xml.Serialization.XmlArrayItem(typeof(DTContractTaxBreakdown))]
in JSON.
i am using newtonsoft.json with c#

Thanks in advance !!!

推荐答案

首先,一定要避免在新代码中使用 ArrayList 。早在.NET v.2.0中,当引入泛型时,这个类就被淘汰了。使用泛型集合,包括 System.Collections.Generic.List<>



请查看我过去的答案关于JSON:

haw从Cloudant(json文档)获取数据 [ ^ ],

如何将多级json数据转换为C#对象? [ ^ ],

如何将对象类型转换为C#类对象类型 [ ^ ],

解析json字符串数组 [ ^ ]。



-SA
First of all, avoid using ArrayList in new code by all means. This class was rendered obsolete as early as of .NET v.2.0, when generics were introduced. Use generic collections, including System.Collections.Generic.List<>.

Please see my past answers on JSON:
haw to get data from Cloudant (json document)[^],
how to conver multi level json data to C# Object?[^],
How To Convert object type to C# class object type[^],
deseralize a json string array[^].

—SA


这篇关于JSON Serializaion到aaray列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆