web services - send complex object json to webservice with jquery -


i'm trying send json object webservice in asp.net $.ajax can't retrive nested object array. client code:

  var fiscaldocument = {              "datetime": "2013-08-07 17:37:41", "operatorname": "admin", "total": 21800              , "fiscallines":             [                 { "id": 254, "itemid": "3", "amount": 1000, "price": 2832, "description": "acqua", "categoryid": 1, "sequence": 0, "type": 1, "categoryname": "bevande", "taxrate": 21000 },                 { "id": 255, "itemid": "3", "amount": 1000, "price": 5024, "description": "acqua", "categoryid": 1, "sequence": 0, "type": 1, "categoryname": "bevande", "taxrate": 21000 },              ],             "paymentlines":             [                 {"paymentform":{"id":1,"name":"creditcard"},"total":1800},                 {"paymentform":{"id":2,"name":"cash"},"total":20000}                 ]             };  $.ajax({         type: "post",         url: "webservice.asmx/exportfiscaldocument",         data: "{'fiscaldocument':" + json.stringify(fiscaldocument) + "}",         contenttype: "application/json; charset=utf-8",         datatype: "json",         success: function (msg) {         alert("ok");        }       }); 

c# code rappresentation of json:

 public class paymentform     {         int id { get; set; }         string name { get; set; }      }      public class paymentline     {         public int total { get; set; }         public paymentform paymentform { get; set; }     }      public class fiscalline     {         public int id { get; set; }         public int itemid { get; set; }         public int amount { get; set; }         public int price { get; set; }         public string description { get; set; }         public int categoryid { get; set; }         public string type { get; set; }         public string categoryname { get; set; }         public int taxrate { get; set; }      }      public class fiscaldocument     {        public string datetime { get; set; }        public string operatorname { get; set; }        public string total { get; set; }        public list<fiscalline> fiscallines { get; set; }        public list<paymentline> paymentlines { get; set; }     }      [webmethod]     public string exportfiscaldocument(fiscaldocument fiscaldocument)     {         return "hello world";     } 

all values okay webservice can't parse data paymentform: fiscaldocument.paymentlines[0].paymentform.id == null :-(

enter image description here

if pass array in way values ok:

[{ "id":1,"name":"creditcard","total":1800}, { "id":1,"name":"cash","total":2000}] 

ok found problem

    public class paymentform     {         int id { get; set; }         string name { get; set; }     } 

i forgot public :-(

    public class paymentform     {         public int id { get; set; }         public string name { get; set; }     } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -