不要查看反序列化的 json (jsonnet) [英] Dont get deserialised json (jsonnet) to be viewed
本文介绍了不要查看反序列化的 json (jsonnet)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我几乎尝试了 2 天,到处搜索以组织下一次.这是我的 json 示例(使用 WebClient => DownloadStringCompletedEventHandler 获取):
Im almost trying for 2 days with searching here and there to get the next organized. This is my json-example (fetched with WebClient => DownloadStringCompletedEventHandler):
{"order_id":"12345678","itemList":["235724","203224","222224","222324","230021"],"amount":["65","50","10","25","42"]}
来自 json2sharp :
From json2sharp :
public class RootObject
{
public string order_id { get; set; }
public List<string> itemList { get; set; }
public List<string> amount { get; set; }
}
我的 Xaml:
<ListBox x:Name="MyListBox" Height="344" Margin="0,107,0,245">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding image}"/>
<TextBlock Text="{Binding order_id}"/>
<TextBlock Text="{Binding itemList}"/>
<TextBlock Text="{Binding amount}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的CS:
private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
return;
}
RootObject rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);
List<RootObject> myItems = rootObject.itemList.;
foreach (var item in myItems)
{
MyListBox.Items.Add(item);
}
Order_id.Text = rootObject.order_id.ToString();
//MyListBox.ItemsSource = Root
//MyListBox.DataContext = RootObject;
}
我可以向 a 显示字符串 order_id,但我没有列出 itemlist + amount.有人可以把我放在正确的方向吗?提前致谢.
Im able to show the string order_id to a , but i dont get listed the itemlist + amount. Can someone put me in the right direction? Thank you in advance.
推荐答案
尝试:
cs:
var result = "{'order_id':'12345678','itemList':['235724','203224','222224','222324','230021'],'amount':['65','50','10','25','42']}";
var rootObject = JsonConvert.DeserializeObject<RootObject>(result);
var items = new List<RootObject>
{
rootObject
};
MyListBox.ItemsSource = items;
xaml:
<ListBox x:Name="MyListBox"
Margin="{StaticResource PhoneMargin}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock>
<TextBlock.Inlines>
<Run Text="order_id:" />
<Run Text="{Binding order_id}" />
</TextBlock.Inlines>
</TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Text="ItemList: " />
<ItemsControl ItemsSource="{Binding itemList}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Amount: " />
<ItemsControl ItemsSource="{Binding amount}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这篇关于不要查看反序列化的 json (jsonnet)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文