JSON not parsed into custom object

前端 未结 1 708
既然无缘
既然无缘 2021-01-29 02:03

Please see the AJAX below:

 
    

        
相关标签:
1条回答
  • 2021-01-29 02:31

    What am I doing wrong?

    Try setting dataType to json instead of text:

    dataType: 'json'
    

    And then send the javascript object as a JSON string in the id parameter:

    window.location.href("JSONExample.aspx?id=" + encodeURIComponent(JSON.stringify(response.d)));
    

    Notice that we are using response.d here because ASP.NET WebMethods serialize the responses using this special property.

    Also you probably want to use public properties instead of fields for your model:

    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
    

    Some frameworks choke on fields.

    0 讨论(0)
提交回复
热议问题