【问题标题】:Show values of WebService tables in message box在消息框中显示 WebService 表的值
【发布时间】:2012-05-17 20:00:49
【问题描述】:

我们想从 WebService 上的 Xml 表中检索惩罚。 我们的代码从第一个表中读取罚分值和第二个表中的罚分值, 但在运行时,它给了我们第一个值 2 次,而不是产生两个表的 2 个不同值。 有谁知道我应该如何编辑我的代码以给出更高的指定结果?这是我的代码:

void pp_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    XElement resultElements = XElement.Parse(e.Result);

    List<StudentPunishment> sp = new List<StudentPunishment>();
    studentPunishmentsTables = resultElements.Element("studentPunishmentsTables").Value;

    string p = s.penalty;

    foreach (XElement nod in resultElements.Elements(@"studentPunishmentsTable"))
    {
        p = resultElements.Element("studentPunishmentsTable").Element("penalty").Value;
        MessageBox.Show(p);
    }
}

【问题讨论】:

  • 我不清楚您要达到的目标。您能否提供一个数据示例(从 Web 请求返回)以及您尝试显示的内容的模型。
  • 01/04/2012课程失败 311First Semester 31/3201/04/2012 issueDate> 学期失败311First Semester 31/32
  • 这是我使用 url 调用它的网络服务..

标签: c# windows-phone-7


【解决方案1】:

这段代码对我来说很好。

foreach (XElement nod in resultElements.Elements(@"studentPunishmentsTable"))
{
        s.penalty = nod.Element("penalty").Value;
        Console.WriteLine(s.penalty);     //MessageBox.Show(s.penalty);
}

但请记住定义 's' 对象实例。

http://prntscr.com/96nbh

【讨论】:

    猜你喜欢
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多