无法将JSON数据绑定到windowsphone 8中的列表

本文关键字:列表 windowsphone JSON 数据绑定 | 更新日期: 2023-09-27 18:28:30

我是手机开发的新手,当我将JSON数据绑定到c#中的列表框时,我会得到一个空白屏幕,我的列表没有被填充,我成功地从web服务获得了JSON响应,我的代码如下

 public void callbackwall(object sender, UploadStringCompletedEventArgs e)
    {
        string json = e.Result.ToString();
        if (!string.IsNullOrEmpty(json))
        {
            var example = JsonConvert.DeserializeObject<List<listreadqueries>>(json);
            ServerList.ItemsSource = example;
         }
        }

    public class readqueriesObject
    {
        public string customer_read_status { get; set; }
        public string description { get; set; }
        public string Inserted_Date { get; set; }
        public string Query_From_Id { get; set; }
        public string Query_From_Name { get; set; }
        public string Query_Id { get; set; }
        public string Query_Status { get; set; }
        public string Query_To_Id { get; set; }
        public string Query_To_Name { get; set; }
        public string title { get; set; }
        public int count { get; set; }
        public List<object> historyList { get; set; }
        public string Query_Type { get; set; }
    }
    public class listreadqueries
    {
        public List<readqueriesObject> queries { get; set; }
    }
}

}

我得到的JSON响应是[{"customer_read_status":"read","description":"Maecenas nec elit metus. Donec porttitor porttitor felis vitae hendrerit. Sed a interdum magna amet.'r'n","Inserted_Date":"Aug 14, 2013 at 01:22"},{....},{..}]

我的XAML代码如下

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,20" Width="300">
                            <TextBlock Text="{Binding Path=description}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>

无法将JSON数据绑定到windowsphone 8中的列表

您的反序列化应该是

var example = JsonConvert.DeserializeObject<List<readqueriesObject>>(json);

无需listreadqueries

PS:您的json是数组,而不是对象约束数组({queries:[...]}