C#和Json帮助 [英] C# and Json help

查看:75
本文介绍了C#和Json帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

需要使用json的这个简单C#/wpf的帮助,试图将某些json文件中名为Hr1的对象的结果获取到列表框中的C#/wpf应用程序中,不确定我在做什么错,希望有人可以阐明这一点吗?

need assistance on this simple C#/wpf with json, trying to get the results from certain objects which are called Hr1 in a json file onto the C#/wpf application in a list box, not sure what i am doing wrong, hopefully someone can shed light on this?

非常感谢:

WPF:

<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="313" Margin="43,45,0,0" VerticalAlignment="Top" Width="298" Grid.Column="1" FontFamily="Times New Roman" Background="White" MouseDoubleClick="listBox_MouseDoubleClick" SelectionMode="Single"  >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

C#:

 private void TreeViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
                    String JNstring = File.ReadAllText("configure.json");

            Connection c = new Connection();

            c.LBMenu = JsonConvert.DeserializeObject<string>(JNstring);

            listBox.ItemsSource = c.LBMenu;


        }

Json:

{
	"Customers": [{
		"C": "Customer Add/Edit/Delete"
	}, {
		"C": "Create Shipping"
	}, {
		"C": "Hours"
	}],
	"Employees": [{
		"Hr": "Employee"
	}, {
		"Hr": "Blah blah"
	}, {
		"Hr": "Hours"
	}],
	"Sales": [{
		"S": "Sales Order"
	}, {
		"S": "Customer"
	}, {
		"S": "Shipping"
	}],
	"PO": [{
		"P": "Purchase Order"
	}, {
		"P": "Customer"
	}, {
		"P": "Receiving"
	}]
}





推荐答案

为什么不采用Json对象并将其转换为List< T> C#个对象并绑定List< T>到控制?

Why wouldn't take the Json objects and convert them over to a List<T> of C# objects and bind the List<T> to the control?

无论如何,应该有一个WPF论坛发布.

Anyway, there is a WPF forum you should post to.

http://social.msdn.microsoft.com/Forums/vstudio /en-US/home?forum = wpf


这篇关于C#和Json帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆