Generics / JSON JavaScriptSerializer C#

后端 未结 2 1703
挽巷
挽巷 2020-12-09 11:47

I\'m building a winForms app in NET3.5SP1 using VS2008Express. Am trying to deserialize an object using the System.Web.Script.Serialization library.

The error is: T

相关标签:
2条回答
  • 2020-12-09 12:30

    It's great you found your error. If you are looking for another tool for JSON serialization you might want to try JSON.Net.

    0 讨论(0)
  • I found my error.. should be:

    Cheers

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    
    // create a generic list of categories
    List<Category> listOfCategories = new List<Category>();
    
    // deserialize as a list of Categories, and put into listOfCategories
    listOfCategories = serializer.Deserialize<List<Category>>(s);
    
    //iterate through list and display in text box
    foreach (Category item in listOfCategories)
    {
        textBox2.Text += item.categoryid.ToString() + "\r\n";
        textBox2.Text += item.name.ToString() + "\r\n";
        textBox2.Text += item.serverimageid.ToString() + "\r\n";
        textBox2.Text += item.dateuploaded.ToString() + "\r\n";
        textBox2.Text += item.enabled.ToString() + "\r\n";
    }
    
    0 讨论(0)
提交回复
热议问题