我是 WP 的新手开发人员。我在解析 json 数据时遇到了一些问题。我从服务器获取它并用 JSON.Net 解析。
JSON 数据示例
{"response":
{"ad6a95dd8f90fad7e281994cb5a8cacd":
{"status":"offline", "name": "Test Name",
"id":"ad6a95dd8f90fad7e281994cb5a8cacd"}
}
"success":true
}
“响应”的第一个选项随对服务器的每个请求而变化。如何提取“名称”字段的值?!预先感谢您的回复。
我在 Page.xaml.cs 中尝试
var o = JObject.Parse(result);
var id = o["response"].First;
ServerList.ItemsSource = id;
并在 Page.xaml
<ScrollViewer Foreground="White">
<ListBox Margin="0,0,-12,0" Name="ServerList" Height="508" Width="415">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,20" Width="300">
<TextBlock Text="{Binding Path=name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
我是通过例子做到的。