读取 coinbase api 时无法在 newtonsoft.Json.LinqJvalue 上获取 child 值?

Unable to get child value on newtonsoft.Json.LinqJvalue when reading coinbase api?

你好,我正在尝试从 URL 获取 coinbase API 汇率,但是 json.net 似乎无法格式化 JSON 文件以供读取children

这是抛出错误的方法

public string CalculateCoinValue(Coinbase connector)
{
    //bool valid = connector.rates.isValid;

    string cryptoExchangeRate;

    if (connector.rates != null)
    {
        cryptoExchangeRate = (string)connector.rates["data"]["currency"]["rates"][Settings.defualtCrypto.ToUpper()];

    }

    return "";
}

这是我用来获取 JSON 数据的方法,该数据将其存储在 Coinbase class

中的 JObject 中
public async Task<JObject> GetExchangeRatesAsync()
{

    HttpClient webClient = new HttpClient();
    string url = string.Format("https://api.coinbase.com/v2/exchange-rates?currency=" + Settings.defaultCurrency);
    HttpResponseMessage coinbaseJsonRaw = await webClient.GetAsync(url);
    return JObject.Parse(await coinbaseJsonRaw.Content.ReadAsStringAsync());
}

我做错了什么导致它不起作用?

返回的json看起来不一样。试试下面的

cryptoExchangeRate = (string)connector["data"]["rates"][Settings.defualtCrypto.ToUpper()];