1

我有这段代码,通过它我从我的本地主机中检索 json 数据。但它给出了我标题中提到的错误。当我在调试时将鼠标悬停在响应上时。它显示了正确的响应。我正在使用 JSON.NET解析 json 响应。

var response = reader.ReadToEnd();

                   List<Company> cLst = JsonConvert.DeserializeObject<List<Company>>(response);    //Error

                    this.Dispatcher.BeginInvoke(() =>
                        {

                            foreach (Company c in cLst)
                            {
                                ListBoxItemControl Li = new ListBoxItemControl();
                                Li.CompanyNameTextBlock.Text = c.CompanyName;
                                Li.PromotionTextBlock.Text = c.PromotionText;
                                listBox1.Items.Add(Li);
                            }
                        });

这是公司类。

class Company
{
    public string CompanyName {get; set;}
    public string CompanySlogan { get; set; }
    public string CompanyDescription { get; set; }
    public string CompanyRating { get; set; }
    public string CompanyDpPath { get; set; }
    public string CompanyOtherInfo { get; set; }
    public string CompanyFollowers { get; set; }
    public int CompanyID { get; set; }

    public int PromotionID { get; set; }
    public string PromotionText { get; set; }
    public string PromotionRating { get; set; }
    public string PromotionPicPath { get; set; }
    public string PromotionTitle { get; set; }
    public int PromotionLikes { get; set; }
    public int PromotionComments { get; set; }



}
4

2 回答 2

1

尝试公开公司课程

于 2012-11-25T15:54:19.980 回答
0

上另一门课,例如,

 public class RootObject
 {
  public List<Company> companies;
 }

然后像这样修改你的代码,

var jsonData = JsonConvert.DeserializeObject<RootObject>(response);
List<Company> cLst = jsonData.companies;

试试这个,让我知道。

于 2012-05-28T12:54:46.593 回答