c# - Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“无法在空引用上执行运行时绑定”
问题描述
我从 OMDB API 获取电影 API,我想将 API 中的数据分配给字符串。
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“无法在空引用上执行运行时绑定” 但我收到此错误。有什么解决办法?
public MainViewModel()
{
SearchCommand = new RelayCommand((e) =>
{
HttpResponseMessage response = new HttpResponseMessage();
var name = SearchText;
response = http.GetAsync($@"http://www.omdbapi.com/?apikey=a91a5037&t={name}&plot=full").Result;
var str = response.Content.ReadAsStringAsync().Result;
Data = JsonConvert.DeserializeObject(str);
MoviePosterPath = Data.Search[0].Poster; // I'm getting errors here
MovieTitle = Data.Search[0].Title;
MovieIMDB = Data.Search[0].imdbRating;
MovieYear = Data.Search[0].Released;
});
}
解决方案
根据您想要获取详细信息的文档Search
。在这种情况下,url 中的参数应该是s
not t
。
response = http.GetAsync($@"http://www.omdbapi.com/?apikey=a91a5037&s={name}&plot=full").Result;
您的其余代码可以保持不变。
推荐阅读
- c# - 清除 Winform 文本框代码片段说明
- java - 如何使用 getAllSelectedOptions 从多个下拉列表中获取选定的选项
- svn - VisualSVN 服务器从 Windows 2008 迁移到 2012(Svn 版本 2.7.14)
- php - SwaggerUI 传递参数
- c# - 用另一个覆盖 IExternal 命令
- python - 如何从 Django 字段中检索数据?
- python - 使用 email.mime 时无法在电子邮件正文中看到 pandas 数据框
- node.js - Node 中 Http Get 的异步使用
- android - 我可以同时使用两个不同的功能从数据库中检索两个文档吗?
- java - OpenAM - 如何在身份验证链中获取先前登录模块的状态