【发布时间】:2019-01-21 17:40:14
【问题描述】:
考虑以下 json:
{
"0": {
"id": "1",
"email": "someemail@test.com",
"tstamp": "2019-01-21 11:19:48",
"times": "2",
"tstamp_iso": "2019-01-21T12:19:48-05:00"
},
"1": {
"id": "2",
"email": "someotheremail@test.com",
"tstamp": "2019-01-21 11:25:48",
"times": "2",
"tstamp_iso": "2019-01-21T12:25:48-05:00"
},
"result_code": 1,
"result_message": "Success!",
"result_output": "json"
}
我正在尝试将该数据转换为 ac# 对象,但是,我不确定如何处理数组值,因为它的名称为 0、1,而不是嵌套在数组中如果有 20 个结果,它将持续到 20。 我无法更改 json 数据。
我已经走到这一步了:
[JsonObject]
public class FirstObject
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "email")]
public string Email { get; set; }
[JsonProperty(PropertyName = "tstamp")]
public string TimeStamp { get; set; }
[JsonProperty(PropertyName = "times")]
public string Times { get; set; }
[JsonProperty(PropertyName = "tstamp_iso")]
public string TimeStampIso { get; set; }
}
[JsonObject]
public class SecondObject
{
public FirstObject[] FirstObjects { get; set; }
[JsonProperty(PropertyName = "result_code")]
public string ResultCode { get; set; }
[JsonProperty(PropertyName = "result_message")]
public string ResultMessage { get; set; }
[JsonProperty(PropertyName = "result_output")]
public string ResultOutput { get; set; }
}
我不明白的是如何将 FirstObjects 映射到 0、1、... 20 的结果。我希望有比写出 20 次并将名称设置为 0 或 1 更好的方法,等等……
【问题讨论】: