这是我的JSON数据
[
{
"market_id": "21",
"coin": "DarkCoin",
"code": "DRK",
"exchange": "BTC",
"last_price": "0.01777975",
"yesterday_price": "0.01770278",
"change": "+0.43",
"24hhigh": "0.01800280",
"24hlow": "0.01752015",
"24hvol": "404.202",
"top_bid": "0.01777975",
"top_ask": "0.01790000"
}
]
这是我的课
public class Model_MarketStats
{
[JsonProperty(PropertyName="market_id")]
public string market_id { get; set; }
[JsonProperty(PropertyName = "code")]
public string code { get; set; }
[JsonProperty(PropertyName = "exchange")]
public string exchange { get; set; }
[JsonProperty(PropertyName = "last_price")]
public string last_price { get; set; }
[JsonProperty(PropertyName = "yesterday_price")]
public string yesterday_price { get; set; }
[JsonProperty(PropertyName = "change")]
public string change { get; set; }
[JsonProperty(PropertyName = "24hhigh")]
public string highest { get; set; }
[JsonProperty(PropertyName = "24hlow")]
public string lowest { get; set; }
[JsonProperty(PropertyName = "24hvol")]
public string volume { get; set; }
[JsonProperty(PropertyName = "top_bid")]
public string top_bid { get; set; }
[JsonProperty(PropertyName = "top_ask")]
public string top_ask { get; set; }
}
错误说
Newtonsoft.Json.JsonSerializationException:不能反序列化当前JSON阵列(例如[1,2,3])转换成类型“MintpalAPI.Model_MarketStats_Root”,因为类型需要JSON对象(例如{“名称”:“值”})给正确反序列化 . 要修复此错误,请将JSON更改为JSON对象(例如{“name”:“value”})或将反序列化类型更改为数组或实现集合接口的类型(例如ICollection,IList),例如List从JSON数组反序列化 . JsonArrayAttribute也可以添加到类型中以强制它从JSON数组反序列化 .
这是我对JSON进行干预的方式
Model_MarketStats = JsonConvert.DeserializeObject<Model_MarketStats>(json);
3 回答
你json是一个数组,使用
您的数据是一个数组,因此,您需要将其反序列化为数组/列表 .
尝试这个,它工作,并使用Newtonsoft.Json包括这个;将json数据转换为字符串并尝试此操作
else将类型转换为json值列表