我有这个 JSON,我在我的代码中从 web 服务执行 GET 并将其解析为字典。
{
"X-YZ-111/AB.CD": {
"P1": "F",
"P2": "43.46"
},
"X-YZ-112/AB.CD": {
"P1": "F",
"P2": "8.02"
},
"X-YZ-113/AB.CD": {
"P1": "F",
"P2": "9066.58"
},
"X-YZ-114/AB.CD": {
"P1": "F",
"P2": "6.00"
},
"X-YZ-115/AB.CD": {
"P1": "F",
"P2": "6.00"
},
"X-YZ-116/AB.CD": {
"P1": "F",
"P2": "10.00"
}}
Using Windows.Data.Json;
private async void getJSON_click(object sender,RoutedEventArgs e)
{
var client=new HttpClient();
client.MaxResponseBufferSize=1024*1024;
var response= await Client.GetAsync(new Uri(The URL here));
var result = await response.Content.ReadAsStringAsync();
var jObj = JObject.Parse(result);
var dict = jObj.Children()
.Cast<JProperty>()
.ToDictionary(p => p.Name,
p => new Tuple<string, string>((string)p.Value["P1"], (string)p.Value["P2"]));
}
我很好奇如何在 dict 对象上实现 iobservable 和 inotifypropertychanged 并将值绑定到 XAML 中的 UI 元素,就像 XAML 中的每个图块将具有名称、P1 和 P2 一样。有什么建议吗?