微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

雅虎财经 API 调用返回空白? Xamarin 表单

如何解决雅虎财经 API 调用返回空白? Xamarin 表单

我正在使用 Xamarin.Forms 进行股票监视列表项目。在我使用 IEX Cloud API 之前收集股票价格,但我正在尝试使用 Yahoo Finance API。我使用以下代码,但 result 返回空白。

namespace Stock_WatchList
{
    public partial class MainPage : ContentPage
    {
        public string ApplePrice { get; set; }
        public string NioPrice { get; set; }
        public string PalantirPrice { get; set; }
        public string TeslaPrice { get; set; }
        public string XpengPrice { get; set; }
        public string AmazonPrice { get; set; }
        public string PinduoduoPrice { get; set; }
        public string disneyPrice { get; set; }
        public string AmdPrice { get; set; }
        public string TwitterPrice { get; set; }

        public MainPage()
        {
            InitializeComponent();


            WebClient yahoo = new WebClient();
            string yahooPrices = yahoo.DownloadString("https://query1.finance.yahoo.com/v7/finance/chart/AAPL?interval=5m ");
            MatchCollection YahooMatches = System.Text.RegularExpressions.Regex.Matches(yahooPrices,@"""([^""]+)"":{""quote"":{""latestPrice"":(\d+(?:.\d+))}}");
            foreach (Match match in YahooMatches)
            {
                switch (match.Groups[1].Value)
                {
                    case "regularMarketPrice":
                        ApplePrice = $"$ {match.Groups[2].Value}";
                        break;
                }
            }

            BindingContext = this;
        }

        private async void ImageButton_Clicked(object sender,EventArgs e)
        {
            await Navigation.PushAsync(new SearchPage());
        }
    }
} 

谁能帮我解决这个问题?

解决方法

我使用 Postman 调用了 yahoo api 并以 json 格式接收了数据。我能够轻松地从该程序中查看数据,我同意 Jason 的观点,在这种情况下,JSON 解析器会为您提供更好的服务。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。