C# 将json中的动态键和值显示到xaml中
下面是我的jsonC# 将json中的动态键和值显示到xaml中,c#,wcf,xaml,windows-phone-8,windows-phone-8.1,C#,Wcf,Xaml,Windows Phone 8,Windows Phone 8.1,下面是我的json {"Hello":[{"CompanyName":"one","ETA":"10","Invoice":{"TF1":" 49","BF1":" 49","MD1":"2 Km","FPk1":" 12","att":"1 mins"},"tf3":"49"},{"CompanyName":"one","ETA":"10","Invoice":{"TF1":" 49","BF1":" 49","MD1":"2 Km","FPk1":" 15","att":"1 mins"},
{"Hello":[{"CompanyName":"one","ETA":"10","Invoice":{"TF1":" 49","BF1":" 49","MD1":"2 Km","FPk1":" 12","att":"1 mins"},"tf3":"49"},{"CompanyName":"one","ETA":"10","Invoice":{"TF1":" 49","BF1":" 49","MD1":"2 Km","FPk1":" 15","att":"1 mins"},"tf3":"49"}],"ChildPresent":true}
我正在反序列化所有内容,我的主要问题是Invoice对象(“Invoice”:{“TF1”:“49”,“BF1”:“49”,“MD1”:“2 Km”,“FPk1”:“15”,“att”:“1分钟”},“tf3”:“49”}]
)包含一堆键和值……问题在于“Invoice”中的键对象,每6小时更改一次…我需要在xaml中显示键和值
现在我正在将上面的json反序列化到Modal中,并将发票对象数据存储到字典中
RootObject j = JsonConvert.DeserializeObject<RootObject>(json);
public class Hello
{
public Dictionary<string, string> Invoice { get; set; }
public string CompanyName {get;set;}
public string ETA {get;set;}
}
public class RootObject
{
public List<Hello> Hello { get; set; }
public bool ChildPresent { get; set; }
}
在xaml中从哪里获得TF1密钥?它是硬编码值吗?是的,在我的列表视图中,我使用了textblock。。。它提供TF1的值请提供XAML代码。另外,
Dictionary
是一个糟糕的绑定解决方案,因为它没有实现INotifyPropertyChanged
,所以您不会看到对Dictionary所做的更改。我在编辑的问题中添加了我的xaml代码……我不明白。您正在XAML中硬编码键的“TF1”值,那么为什么不在文本块中直接显示“TF1”?当您可以执行Text=“TF1”
时,尝试执行Text=“{Binding Invoice[TF1].Key}”
有什么意义?
<Page x:Class="App13.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App13"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:converter="using:App13"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Margin="0,30.333,0,-0.333" Background="Black">
<ListView IsItemClickEnabled="True" IsEnabled="True"
ItemClick="listview1_ItemClick"
ScrollViewer.VerticalScrollMode="Enabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
x:Name="listview1" ItemsSource="{Binding Hello}"
FontSize="17" Margin="10,0,-10,0">
<ListView.Items>
</StackPanel>
</ListView.Items>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Border Tapped="Border_Tap" Height="90">
<StackPanel x:Name="ParentStackPanel"
Width="380" Margin="0,5,0,5">
<StackPanel Background="Black"
Margin="60,-80,0,0"
Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Left">
<TextBlock Text="{Binding CompanyName}"
FontSize="20"
FontStyle="Normal">
</TextBlock>
<TextBlock Text="{Binding ETA}"
FontSize="16"
FontStyle="Normal">
</TextBlock>
</StackPanel>
<StackPanel Margin="0,-80,0,0"
Background="Black"
Grid.Column="0"
Grid.Row="0"
VerticalAlignment="Center"
HorizontalAlignment="Left">
<Image Width="48"
Height="48"
Source="{Binding Icon}" />
</StackPanel>
<StackPanel Name="expand"
Background="White"
Height="220">
<StackPanel Orientation="Horizontal"
Margin="10,10,0,0">
<TextBlock AllowDrop="True"
Grid.Column="1"
Margin="50,0,0,0"
HorizontalAlignment="Left"
FontSize="10"
Foreground="Black"
Text="{Binding Invoice[TF1].Key}">
</TextBlock>
<TextBlock Name="tb"
Grid.Column="2"
HorizontalAlignment="Right"
AllowDrop="True"
FontSize="6"
Foreground="Black"
Width="204"
Text="{Binding Path=Invoice[TF1]}">
</TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Margin="0,5,0,5"
Height="5"
Grid.Row="1"
Background="Aqua"
x:Name="something">
</StackPanel>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>