Windows phone 7 在xaml中从Json进行数据绑定?

Windows phone 7 在xaml中从Json进行数据绑定?,windows-phone-7,xaml,data-binding,json.net,Windows Phone 7,Xaml,Data Binding,Json.net,我正在制作一个WP7应用程序,并以json的形式从我的webapi获取数据。我想知道我怎样才能把它数据绑定起来?我需要创建一个具体的类还是可以使用JArray [{"Id":"fe480d76-deac-47dd-af03-d5fd524f4086","Name":"SunFlower Seeds","Brand":"PC"}] JArray jsonObj = JArray.Parse(response.Content); this.listBox.ItemsSource = js

我正在制作一个WP7应用程序,并以json的形式从我的webapi获取数据。我想知道我怎样才能把它数据绑定起来?我需要创建一个具体的类还是可以使用JArray

[{"Id":"fe480d76-deac-47dd-af03-d5fd524f4086","Name":"SunFlower Seeds","Brand":"PC"}]

  JArray jsonObj = JArray.Parse(response.Content);
   this.listBox.ItemsSource = jsonObj;


        <ListBox x:Name="listBox" FontSize="26" Margin="0,67,0,0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Id}" Width="100"/>
                        <TextBlock Text="{Binding Brand}" Width="100"/>
                        <TextBlock Text="{Binding Name}" Width="100"/>
                    </StackPanel>

                </DataTemplate>

            </ListBox.ItemTemplate>

        </ListBox>
[{“Id”:“fe480d76-deac-47dd-af03-d5fd524f4086”,“名称”:“葵花籽”,“品牌”:“PC”}]
JArray jsonObj=JArray.Parse(response.Content);
this.listBox.ItemsSource=jsonObj;

使用WPF绑定时,需要使用属性。创建强类型对象,然后反序列化JSON

创建您的对象:

public class MyObject
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Brand { get; set; }
}
下面是一个非常松散的绑定示例,它基于您指示如何设置列表框的ItemsSource:

string json = "[{\"Id\":\"fe480d76-deac-47dd-af03-d5fd524f4086\",\"Name\":\"SunFlower Seeds\",\"Brand\":\"PC\"}]";

var jsonObj = JArray.Parse( json );

var myObjects = jsonObj.Select( x => JsonConvert.DeserializeObject<MyObject>( x.ToString() ) );

this.listBox.ItemsSource = myObjects;
string json=“[{\'Id\”:\“fe480d76-deac-47dd-af03-d5fd524f4086\”,“Name\”:“葵花籽\”,“Brand\”:“PC\”);
var jsonObj=JArray.Parse(json);
var myObjects=jsonObj.Select(x=>JsonConvert.DeserializeObject(x.ToString());
this.listBox.ItemsSource=myObject;
注意:我没有使用json.net,因此可能有一种更好的方法可以使用json.net对数组进行反序列化,正如我所发布的那样