我已经能够序列化一个JSON数组,如下所示:
[
{
"AssociatedOrders": [
{
"ID": {
"Value": 0
},
"TransactionReferences": {
"Authorization": ""
},
"ShipToName": ""
}
],
"BillToCustomer": {
"Value": "0"
},
"ID": {
"Value": 0
},
"Lines": [
{
"Amount": 0,
"Description": "",
"OrderID": {
"Value": 0
}
}
],
"PayerName": "",
"PaymentDate": "",
"PaymentMethod": "",
"PaymentReferenceNumber": ""
},
{
"AssociatedOrders": [
{
"ID": {
"Value": 0
},
"TransactionReferences": {
"Authorization": ""
},
"ShipToName": ""
}
],
"BillToCustomer": {
"Value": "0"
},
"ID": {
"Value": 0
},
"Lines": [
{
"Amount": 0,
"Description": "",
"OrderID": {
"Value": ""
}
}
],
"PayerName": "",
"PaymentDate": "",
"PaymentMethod": "",
"PaymentReferenceNumber": ""
}
]
WebAPI调用返回IEnumerable>但是当我尝试使用
进行反序列化时JsonConvert.DeserializeObject<IEnumerable<SomeClass<SomeOtherClass>>>(data, JsonSerializerSettings);
其中data是返回的json字符串,json序列化器设置设置为
{
Formatting = Formatting.None,
TypeNameHandling = TypeNameHandling.Auto
};
请求崩溃并出现以下错误:
Error reading JObject from JsonReader. Current JsonReader item is not an object: Float.
从我读过的数据来看,这个数组是一个JsonArray(JArray
)。但是,我如何能够遍历此JArray并确保将值适当地映射到SomeClass<SomeOtherClass>
构造?
如何在JArray
中正确读取以便映射对象属性?
解决:
原来这实际上是一个过时的参考问题。我返回JSON的API使用的是比客户端更新的软件包版本。因此,客户端认为返回类型的类型为NodaMoney.Money
,而在更新的包中它是decimal
。我所做的就是更新客户端软件包,一切正常。以为我会取消删除帖子,所以人们不会犯同样的错误。在这方面浪费了这么多时间,哦,好的,吸取了教训。