0

我有一个轻微的逻辑问题。我正在解析从 api 调用返回的 XML 文件以显示在列表框中。xml 数据返回一个对象键而不是实际图像。然后,我必须使用 opject 键调用另一个函数,该函数返回带有图像数据的 xml,解析该图像数据并将其返回给前一个函数。我能够成功地将数据解析为 IEnumerable 列表,但我不确定如何将图像字符串返回到上一个调用。

                try
                {
                   // MessageBox.Show(response.Content);
                    XDocument streamFeed = XDocument.Load(new StringReader(response.Content));
                    var data = from query in streamFeed.Descendants("interaction")
                               select new Interaction
                               {
                                   title = (string)query.Element("title"),
                                   displayName = (string)query.Element("displayName"),
                                   action = (string)query.Element("action"),
                                   verb = (string)query.Element("verb"),
                                   userId = (string)query.Element("userId"),
                                   objectKey = (string)query.Element("objectKey"),
                                   timestamp = (string)query.Element("timestamp"),
                                   comment = (string)query.Element("comment"),
                                   source = (string)query.Element("source"),                            
                                   profileImage = "http://adb.s3.amazonaws.com/" + (string)query.Element("userId") + "/avatar.png",
                                   image = getImage((string)query.Element("objectKey")),
                               };



                    streamListBox.ItemsSource = data;

上面的代码片段是第一个将数据绑定到列表框的函数。这很好用,除了我需要不在 xml 响应中的图像。我必须进行第二个函数调用 - getImage- 以使用对象键获取它。我希望 getImage 函数只返回每个对象的字符串

                    try
                    {
                       // MessageBox.Show(response.Content);
                        XDocument streamFeed = XDocument.Load(new StringReader(response.Content));



                        var data = from query in streamFeed.Descendants("show")
                                   select new Interaction
                                   {
                                       image = (string)query.Element("image"),
                                   };

                        var data2 = from query in streamFeed.Descendants("movie")
                                    select new Interaction
                                    {
                                        image = (string)query.Element("image"),
                                    };

                        var data3 = from query in streamFeed.Descendants("artist")
                                    select new Interaction
                                    {
                                        image = (string)query.Element("image"),
                                    };



                        objImages = data.Concat(data2).Concat(data3);


                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }

                });
            }
            return "HOW CAN I RETURN IMAGE STRING HERE";
        }
4

0 回答 0