【发布时间】:2015-09-17 15:14:02
【问题描述】:
我使用 JSON.Net。
我为预期的 Json 写了一个强类型表示:
public BaseClass{
[JsonProperty("fields")]
public Fields Fields { get; set; }
}
public class Fields
{
[JsonProperty("worklog")]
public List<WorkLog> WorkLog { get; set; }
}
预期的 Json 示例:
{
"baseprop": {
"fields": {
"worklog": {
"startAt": 0,
"maxResults": 20,
"total": 2,
"worklogs": [
{
"self": "",
"author": {},
"updateAuthor": {},
"comment": "UpdatedcouriersT&C",
"created": "2015-09-04T19: 11: 27.169+0300",
"updated": "2015-09-04T19: 13: 00.567+0300",
"started": "2015-09-04T19: 11: 00.000+0300",
"timeSpent": "1h",
"timeSpentSeconds": 3600,
"id": ""
},
{
"self": "",
"author": {},
"updateAuthor": {},
"comment": "",
"created": "2015-09-07T10: 26: 23.549+0300",
"updated": "2015-09-07T10: 26: 23.549+0300",
"started": "2015-09-07T10: 26: 00.000+0300",
"timeSpent": "10m",
"timeSpentSeconds": 600,
"id": ""
}
]
}
}
}
}
如何从“baseprop”元素中获取属性“worklogs”的值?
我尝试了类似"[JsonProperty("worklog/worklogs")]" 的方法,但这不起作用。
JsonProperty 支持这种东西吗?
谢谢
【问题讨论】:
-
“如果我在 baseprop 中”是什么意思?很难准确地说出您在做什么,尤其是您的
Fields课程似乎与您提供的 JSON 没什么关系... -
@JonSkeet,我更新了问题。我反序列化我的 json 并使用
JsonProperty我将我的类“绑定”到 json 属性。所以我想从fields跳过一步到worklogs(跳过属性worklog) -
您的 JSON 看起来不完整;您所显示的内容无效。见jsonlint.com
-
@BrianRogers,现在可以了