0

我正在使用这种方法来获取数据

 private void getNews(int cat_id, int page)
    {
        this.progress.Visibility = Visibility.Visible;
        var m = new SharpGIS.GZipWebClient();
        Microsoft.Phone.Reactive.Observable.FromEvent<DownloadStringCompletedEventArgs>(m, "DownloadStringCompleted").Subscribe(l =>
        {
            try
            {
                //List<NewsKeys> deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(r.EventArgs.Result);
                ObservableCollection<NewsKeys> deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(l.EventArgs.Result);

                foreach (NewsKeys item in deserialized)
                {
                    items.Add(new NewsKeys { nId = item.nId, title = item.title, shortDesc = item.shortDesc, fullDesc = item.fullDesc, tags = item.tags, smallPic = item.smallPic, bigPic = item.bigPic, video = item.video, audio = item.audio, youtube = item.youtube, doc = item.doc, date_create = item.date_create, date_modify = item.date_modify, date_publish = item.date_publish, catId = item.catId, viewOrder = item.viewOrder, viewCount = item.viewCount, viewStatus = item.viewStatus, viewHome = item.viewHome, uId = item.uId, uFname = item.uFname });
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Sorry, Some unexpected error.");
            }
        });
        m.DownloadStringAsync(new Uri(Resource.NEWS_API+cat_id+"&page="+page));
    }

我得到的错误是

错误 1 ​​无法将 lambda 表达式转换为类型“System.IObserver>”,因为它不是委托类型 C:\Users\Adodis\Documents\Visual Studio 2010\Projects\TV\NewsListPage.xaml.cs 51 133

我已经尝试了所有的修复,但无法解决这个问题。我在不同的类中以不同的方法使用相同的块,它工作正常,但是,这个类中的这个方法让我死了。如果您对此有任何想法,请帮助我。

提前致谢。

4

1 回答 1

0

试试这个(我已经分离了SelectSubscribe操作):

var m = new SharpGIS.GZipWebClient();

Observable.FromEvent<DownloadStringCompletedEventArgs>(m, "DownloadStringCompleted")
          .Select(l => l.EventArgs.Result)
          .Subscribe(res =>
              {
                  try
                  {
                      var deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(res);

                      foreach (NewsKeys item in deserialized)
                      {
                          items.Add(
                              new NewsKeys
                                  {
                                      nId = item.nId,
                                      title = item.title,
                                      shortDesc = item.shortDesc,
                                      fullDesc = item.fullDesc,
                                      tags = item.tags,
                                      smallPic = item.smallPic,
                                      bigPic = item.bigPic,
                                      video = item.video,
                                      audio = item.audio,
                                      youtube = item.youtube,
                                      doc = item.doc,
                                      date_create = item.date_create,
                                      date_modify = item.date_modify,
                                      date_publish = item.date_publish,
                                      catId = item.catId,
                                      viewOrder = item.viewOrder,
                                      viewCount = item.viewCount,
                                      viewStatus = item.viewStatus,
                                      viewHome = item.viewHome,
                                      uId = item.uId,
                                      uFname = item.uFname
                                  });
                      }
                  }
                  catch (Exception)
                  {
                      MessageBox.Show("Sorry, Some unexpected error.");
                  }
              });

m.DownloadStringAsync(new Uri("Resource.NEWS_API" + cat_id + "&page=" + page));
于 2013-03-13T13:22:06.373 回答