繁体   English   中英

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“无法在 null 参考上执行运行时绑定”

[英]Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Unable to execute runtime binding on null reference'

我从 OMDB API 得到电影 API,我想将 API 中的数据分配给字符串。

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:“无法在 null 参考上执行运行时绑定”但我收到此错误。 有什么解决办法?

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而不是t

response = http.GetAsync($@"http://www.omdbapi.com/?apikey=a91a5037&s={name}&plot=full").Result;

你代码的rest可以保持不变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM