我在解析 JSON 以在 C# 中列出时遇到问题。我正在使用 Json.net 来解析 json。我的问题是我收到错误“将值“高”转换为类型时出错”。请帮我。
我的json:
{"sold":{"high":40.64625,"low":35.02,"avg":37.929384985,"buy":40.28,"sell":40.3}}
我的代码:
public class sold
{
public string high { get; set; }
public string low { get; set; }
public string avg { get; set; }
public string buy { get; set; }
public string sell { get; set; }
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
JObject something = JObject.Parse(e.Result);
IList<JToken> results = something["sold"].Children().ToList();
IList<sold> searchResults = new List<sold>();
foreach (JToken result in results)
{
sold searchResult = JsonConvert.DeserializeObject<sold>(result.ToString());
searchResults.Add(searchResult);
}