好的,所以我之前一直被 JSON.NET 困住,但我又被困住了,多亏了你们帮助我的最后一个问题,我成功地完成了我的项目:3。但是现在我需要反序列化一段实际上没有密钥的 JSON。好吧,但它是一个整数,它可以在 0 - 50 之间变化,这意味着我不知道如何做到这一点。我尝试使用 IDictionary,但失败得很惨……无论如何,这是 JSON:
{
"response": {
"success": 1,
"current_time": 1362339098, // this will return the time when cache was generated
"prices": {
"35": { // defindex
"11": { // quality
"0": { // price index ( crate # or unusual effect, 0 when not used )
"current": { // current price
"currency": "keys",
"value": 39,
"value_high": 41,
"date": 1357515306 // date when the price was updated
},
"previous": { // previous price
"currency": "keys",
"value": 37,
"value_high": 39
}
}
},
"3": { // quality
"0": { // price index
"current": {
"currency": "metal",
"value": 0.33,
"value_high": 0.66
}
}
}
},
"5002": { // refined metal, useful for converting usd prices into metal
"6": {
"0": {
"current": {
"currency": "usd",
"value": 0.39,
"value_high": 0.42,
"date": 1358090106
}
}
}
},
"5022": { // one of the crate defindex
"6": {
"1": { // crate #1
"current": {
"currency": "metal",
"value": 1.33,
"value_high": 1.55,
"date": 1357515175
}
}
}
}
}
}
}
(数据格式......再次......)
这是我可悲的尝试:
public class Json1 {
public Json2 response { get; set; }
}
public class Json2 {
public int success { get; set; }
public string current_time { get; set; }
public IDictionary<int, Json3> prices { get; set; }
}
public class Json3 {
}
public class Json4 {
}
public class Json5 {
public Json6 current { get; set; }
}
public class Json6 {
public string currency { get; set; }
public string value { get; set; }
public string value_high { get; set; }
}
Json 3 和 4 是空的,因为我不断删除以尝试不同的东西......
但是,是的......我已经习惯了 json,但无法弄清楚这一点。任何友好的回应都非常感谢提前。
(我知道我在一些浮点数和长整数上使用了字符串,这是故意的,但我想可以更改)