0

我是电话开发新手,当我将 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>
4

1 回答 1

1

你的反序列化应该是

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

不需要listreadqueries

PS:你的 json 是一个数组,而不是一个包含数组的对象({queries:[...]}

于 2013-08-21T10:12:21.253 回答