【发布时间】:2015-02-06 05:11:16
【问题描述】:
我有一个 json 字符串:
{"GetOrderListResponse":
{"orderListResponse":
{
"orderDetails":
[
{"order":
{
"orderId":208,
"legDetails":
{
"legNumber":1,
"symbolInfo":
{
"symbol":"CSCO"
}
}
}
},
{"order":
{
"orderId":200,
"legDetails":
[
{
"legNumber":1,
"symbolInfo":
{
"symbol":"IBM"
}
},
{
"legNumber":2,
"symbolInfo":
{
"symbol":"IBM",
"callPut":"CALL",
"expYear":2010,
"expMonth":4,
"expDay":17,
"strikePrice":115
}
}
]
}
}
]
}
}
}
我有对象
public class OrderListResponse
{
public List<OrderDetail> orderDetails { get; set; }
}
public class OrderDetail
{
public Order order { get; set; }
}
public class Order
{
public long orderId { get; set; }
public List<LegDetail> legDetails { get; set; }
}
public class LegDetail
{
public long legNumber { get; set; }
public Symbol symbolInfo { get; set; }
}
public class Symbol
{
public string symbol { get; set; }
public string callPut { get; set; }
public int expYear { get; set; }
public int expMonth { get; set; }
public int expDay { get; set; }
public int strikePrice { get; set; }
}
所以当我使用代码时:
var objectValue = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, object>>>(jsonString);
var objectDeserialize = JsonConvert.DeserializeObject<OrderListResponse>(objectValue.Values.First()["orderListResponse"].ToString());
我收到一条错误消息:
无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1[LegDetail]' 因为该类型需要 JSON 数组(例如 [1,2 ,3]) 正确反序列化。
谁能告诉我正确的代码让它工作?
【问题讨论】:
标签: c# json deserialization json-deserialization