C# 具有数据的对象的JsonString不是数组

C# 具有数据的对象的JsonString不是数组,c#,json,serialization,C#,Json,Serialization,我从公共web中的API获取数据,该API返回一个JSONString,如下所示: `{ "data": [ { "id": 1, "name": "Bitcoin", "symbol": "BTC", "website_slug": "bitcoin", "rank": 1, "circulating_supply": 17080450.0, "total_sup

我从公共web中的API获取数据,该API返回一个JSONString,如下所示:

`{
"data": [
    {
        "id": 1, 
        "name": "Bitcoin", 
        "symbol": "BTC", 
        "website_slug": "bitcoin", 
        "rank": 1, 
        "circulating_supply": 17080450.0, 
        "total_supply": 17080450.0, 
        "max_supply": 21000000.0, 
        "quotes": {
            "USD": {
                "price": 7675.65, 
                "volume_24h": 4815480000.0, 
                "market_cap": 131103556043.0, 
                "percent_change_1h": -0.24, 
                "percent_change_24h": 0.72, 
                "percent_change_7d": 1.48
            }, 
            "BTC": {
                "price": 1.0, 
                "volume_24h": 627370.9718395185, 
                "market_cap": 17080450.0, 
                "percent_change_1h": 0, 
                "percent_change_24h": 0, 
                "percent_change_7d": 0
            }
        }, 
        "last_updated": 1528385974
    }, 
    {
        "id": 2, 
        "name": "Litecoin", 
        "symbol": "LTC", 
        "website_slug": "litecoin", 
        "rank": 6, 
        "circulating_supply": 56877198.0, 
        "total_supply": 56877198.0, 
        "max_supply": 84000000.0, 
        "quotes": {
            "USD": {
                "price": 120.933, 
                "volume_24h": 356821000.0, 
                "market_cap": 6878330197.0, 
                "percent_change_1h": -0.27, 
                "percent_change_24h": -0.06, 
                "percent_change_7d": 1.1
            }, 
            "BTC": {
                "price": 0.0157554083, 
                "volume_24h": 46487.3984613681, 
                "market_cap": 896123.0, 
                "percent_change_1h": -0.03, 
                "percent_change_24h": -0.78, 
                "percent_change_7d": -0.38
            }
        }, 
        "last_updated": 1528385943
    }
], 
"metadata": {
    "timestamp": 1528385873, 
    "num_cryptocurrencies": 1645, 
    "error": null
}
}`
我已经创建了一个类来从这个API获取数据,这是我的代码:

public class CryCurClass
{
    [JsonProperty("data")]
    public List<data> data;

    [JsonProperty("metadata")]
    public object metadata;
}

public class data
{
    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("symbol")]
    public string Symbol { get; set; }

    [JsonProperty("website_slug")]
    public string Website_slug { set; get; }

    [JsonProperty("rank")]
    public int Rank { get; set; }

    [JsonProperty("circulating_supply")]
    public Nullable<float> Circulating_supply { get; set; }

    [JsonProperty("total_supply")]
    public float Total_supply { get; set; }

    [JsonProperty("max_supply")]
    public Nullable<float> Max_supply { get; set; }

    [JsonProperty("qoutes")]
    public Qoutes Qoutes { set; get; }

    [JsonProperty("last_updated")]
    public string Last_updated { get; set; }

}

public class Qoutes
{
    [JsonProperty("USD")]
    public info USD { set; get; }
    [JsonProperty("BTC")]
    public info BTC {set;get ;}
}

public class info
{
    [JsonProperty("price")]
    public Nullable<float> Price { set; get; }

    [JsonProperty("volume_24h")]
    public Nullable<float> Volume_24h { set; get; }

    [JsonProperty("market_cap")]
    public Nullable<float> Market_cap { set; get; }

    [JsonProperty("percent_change_1h")]
    public Nullable<float> Percent_change_1h { set; get; }

    [JsonProperty("percent_change_24h")]
    public Nullable<float> Percent_change_24h { set; get; }

    [JsonProperty("percent_change_7d")]
    public Nullable<float> Percent_change_7d { set; get; }
}
公共类CryCurClass
{
[JsonProperty(“数据”)]
公开名单数据;
[JsonProperty(“元数据”)]
公共对象元数据;
}
公共类数据
{
[JsonProperty(“id”)]
公共字符串Id{get;set;}
[JsonProperty(“名称”)]
公共字符串名称{get;set;}
[JsonProperty(“符号”)]
公共字符串符号{get;set;}
[JsonProperty(“网站”\u slug”)]
公共字符串网站_slug{set;get;}
[JsonProperty(“rank”)]
公共整数秩{get;set;}
[JsonProperty(“循环供应”)]
公共可空循环_供应{get;set;}
[JsonProperty(“总供应量”)]
公共浮动总供给{get;set;}
[JsonProperty(“最大供应量”)]
公共可空的最大供应量{get;set;}
[JsonProperty(“qoutes”)]
公共Qoutes Qoutes{set;get;}
[JsonProperty(“上次更新”)]
上次更新的公共字符串{get;set;}
}
公共类Qoutes
{
[JsonProperty(“美元”)]
公共信息USD{set;get;}
[JsonProperty(“BTC”)]
公共信息BTC{set;get;}
}
公共类信息
{
[JsonProperty(“价格”)]
公共可空价格{set;get;}
[JsonProperty(“24小时卷”)]
公共可空卷_24h{set;get;}
[JsonProperty(“市值”)]
公开可为空的市场{set;get;}
[JsonProperty(“变化百分比”)]
公共可空百分比\u更改\u 1h{set;get;}
[JsonProperty(“24小时变化百分比”)]
公共可空百分比\u更改\u 24小时{set;get;}
[JsonProperty(“变化百分比”)]
公共可空百分比\u更改\u 7d{set;get;}
}
但是当我尝试将JsonString转换为class时,代码为:
CryCurClass jsonClass=JsonConvert.DeserializeObject(\u strAnswer)变量Qoutes始终返回null。我意识到这个变量不是一个常规数组,但我不知道如何构建类来包含它。

我认为我的类与这个JSonString不匹配,但我不知道如何修复它。

是因为你的Qoutes中有拼写错误吗?在Json中,有引号,类名是Qoutes

为了简单起见,请使用此站点从Json生成类。

公共类美元
{
公共双价{get;set;}
公共双卷_24h{get;set;}
公开双市场{get;set;}
公共双百分比变化{get;set;}
公共双百分比\u更改\u 24小时{get;set;}
公共双百分比\u更改\u 7d{get;set;}
}
公共级BTC
{
公共双价{get;set;}
公共双卷_24h{get;set;}
公开双市场{get;set;}
公共双百分比变化{get;set;}
公共双百分比\u更改\u 24小时{get;set;}
公共双百分比\u更改\u 7d{get;set;}
}
公共类引用
{
公共美元{get;set;}
公共BTC BTC{get;set;}
}
公共类数据
{
公共int id{get;set;}
公共字符串名称{get;set;}
公共字符串符号{get;set;}
公共字符串网站_slug{get;set;}
公共整数秩{get;set;}
公共双循环_供应{get;set;}
公共双总供给{get;set;}
公共双最大值供应{get;set;}
公共引号{get;set;}
上次更新的公共int{get;set;}
}
公共类元数据
{
公共int时间戳{get;set;}
public int num_加密货币{get;set;}
公共对象错误{get;set;}
}
公共类根对象
{
公共列表数据{get;set;}
公共元数据{get;set;}
}

JSON API返回一个名为“quotes”的对象。
您的反序列化对象正在寻找一个名为“qoutes”的对象。

是的,我的错:很高兴我能帮上忙。你能接受这个答案吗?所以,我可以帮助别人。
public class USD
{
    public double price { get; set; }
    public double volume_24h { get; set; }
    public double market_cap { get; set; }
    public double percent_change_1h { get; set; }
    public double percent_change_24h { get; set; }
    public double percent_change_7d { get; set; }
}

public class BTC
{
    public double price { get; set; }
    public double volume_24h { get; set; }
    public double market_cap { get; set; }
    public double percent_change_1h { get; set; }
    public double percent_change_24h { get; set; }
    public double percent_change_7d { get; set; }
}

public class Quotes
{
    public USD USD { get; set; }
    public BTC BTC { get; set; }
}

public class Datum
{
    public int id { get; set; }
    public string name { get; set; }
    public string symbol { get; set; }
    public string website_slug { get; set; }
    public int rank { get; set; }
    public double circulating_supply { get; set; }
    public double total_supply { get; set; }
    public double max_supply { get; set; }
    public Quotes quotes { get; set; }
    public int last_updated { get; set; }
}

public class Metadata
{
    public int timestamp { get; set; }
    public int num_cryptocurrencies { get; set; }
    public object error { get; set; }
}

public class RootObject
{
    public List<Datum> data { get; set; }
    public Metadata metadata { get; set; }
}