我正在开发一个移动空气应用程序。为了进行交流,我正在使用WCF服务。现在我的问题是,我正在尝试使用json.net进行一系列数组的序列化。子阵列被键入。因此,我在移动方面的课程如下:
package Model.VO.PHCDATA
{
[Bindable]
[RemoteClass(alias="Model.PCHModel.VODadosPHC")]
public class VoBi
{
private var _BIstamp:String;
private var _ivaincl:Number;
private var _vendnm:String;
private var _vendedor:Number;
private var _iva:Number;
private var _lordem:Number;
private var _tabiva:Number;
private var _txiva:Number;
private var _familia:String;
....
}
}
,另一个是:
package Model.VO.PHCDATA
{
[Bindable]
[RemoteClass(alias="Model.PCHModel.VODadosPHC")]
public class VOBO
{
private var _BOstamp:String;
private var _vendedor:Number;
private var _vendnm:String;
....
}
}
和相应的C#类如下:
[DataContract(Name = "VoBi")]
public class VoBi
{
[DataMember(IsRequired = true, Name = "BIstamp", Order = 0)]
public string BIstamp { get; set; }
[DataMember(IsRequired = true, Name = "ivaincl", Order = 1)]
public decimal ivaincl { get; set; }
[DataMember(IsRequired = true, Name = "vendnm", Order = 2)]
public string vendnm { get; set; }
[DataMember(IsRequired = true, Name = "vendedor", Order = 3)]
public decimal vendedor { get; set; }
....
}
和另一个:
[DataContract(Name = "VOBO")]
public class VOBO
{
[DataMember(IsRequired = true, Name = "BOstamp", Order = 0)]
public string BOstamp { get; set; }
[DataMember(IsRequired = true, Name = "vendedor", Order = 1)]
public decimal vendedor { get; set; }
[DataMember(IsRequired = true, Name = "vendnm", Order = 2)]
public string vendnm { get; set; }
[DataMember(IsRequired = true, Name = "nmdos", Order = 3)]
public string nmdos { get; set; }
[DataMember(IsRequired = true, Name = "ndos", Order = 4)]
public decimal ndos { get; set; }
.....
}
要发送到服务器的相应的JSON字符串是:
{
"DADOSBI": [
{
"edebito": 0,
"desconto": 92.121,
"vendedor": 0,
"desc2": 222.343,
"iva": 23,
"ettdeb": 123.555,
"lordem": 12,
"tabiva": 2.1,
....
},
{
"edebito": 0,
"desconto": 92.121,
"vendedor": 1,
"desc2": 222.343,
"iva": 23,
"ettdeb": 123.555,
"lordem": 12,
"tabiva": 2.1,
....
}
],
"DADOSBO": [
{
"estab": 123.88,
"etotaldeb": 123,
"obs": "",
"vendedor": 0,
"statuspda": "qqqqqqqqqqqq",
"ebo_2tvall": 12,
"ebo_2tdes1": 12.11,
...
},
{
"estab": 123.88,
"etotaldeb": 123,
"obs": "",
"vendedor": 1,
"statuspda": "qqqqqqqqqqqq",
"ebo_2tvall": 12,
....
}
]
}
我该如何处理?我是否使用JSON.NET CustomCreationConverter来启用数据?并获取填充我提到的类的相应阵列,还是我使用另一种方法?帮助您将不胜感激。预先感谢。
假设您的顶级班级看起来如下(如果您没有的话,如果努力较少,否则我们需要做一个更好的解决方案)
internal class TopClass
{
[JsonProperty("DADOSBI")]
public IList<VoBi> VOBiList { get; set; }
[JsonProperty("DADOSBO")]
public IList<VOBO> VOBOList { get; set; }
}
然后简单地使用
进行挑选var topClass = JsonConvert.DeserializeObject<TopClass>( json);
如果这不是您要寻找的答案,请使用更多信息更新问题