【发布时间】:2011-09-19 10:05:21
【问题描述】:
关于如何使用 Json.Net 将以下响应反序列化为匿名类型的任何想法?
{"d":[{"day":"Wednesday","firstSet":{"start":"17:00","close":"23:00","hours":6,"isValid":true},"secondSet":{"start":"00:00","close":"00:00","hours":0,"isValid":false},"personMinimum":2,"personMaximum":25}]}
到目前为止的尝试导致以下错误
无法从 System.String 转换或转换为 f__AnonymousType35[System.String,<>f__AnonymousType24[System.String,System.String,System.Int32,System.Boolean],f__AnonymousType2`4[System.String,System. String,System.Int32,System.Boolean],System.Int32,System.Int32].
代码如下
var json_complex = new
{
d = new
{
day = "",
firstSet = new
{
start = "",
close = "",
hours = 0,
isValid = false
},
secondSet = new
{
start = "",
close = "",
hours = 0,
isValid = false
},
personMinimum = 2,
personMaximum = 25
}
};
var json = JsonConvert.DeserializeAnonymousType(jsonResponse, json_complex);
有什么想法吗?
【问题讨论】:
-
查看 stackoverflow [post][1] 关于使用 Json.NET 将 JSON 反序列化为对象的答案 [1]:stackoverflow.com/questions/2555363/…
标签: asp.net json serialization anonymous-types json.net