c# - Yahoo Finance 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 解析器会更好地为您服务。
推荐阅读
- javascript - 从 JavaScript 对象属性创建表单
- sql - 分页中的性能调整(SQL 查询)
- python - 如何在 tkinter 中进行简单的倒计时?
- angular - PrimeNG 日历
- 如何禁用 UTC - Z 时区 - c - 程序比较两个整数数组 a 和 b 的元素,并将元素存储在数组 c 中,这些元素在 a 或 b 中,但不在 a 和 b 中
- go - 按引用或按值扫描函数
- python - 将热图添加到 Folium 中的图层
- xml - 将 xml 反序列化为对象时,我保持为空
- java - 将(自动生成的?)EJB 代码从 Websphere 转换为 Glassfish
- c++ - Qt5 paintEvent() 区域太小