-1

$.ajax で json オブジェクトを asp.net の webservice に送信しようとしていますが、ネストされたオブジェクトを配列に取得できません。クライアントコード:

  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");
       }
      });

JSON の C# コード表現:

 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";
    }

すべての値に問題はありませんが、Web サービスはデータを PaymentForm に解析できません: Fiscaldocument.paymentlines[0].paymentform.id == NULL :-(

ここに画像の説明を入力

この方法で配列を渡すと、値は問題ありません。

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

1 に答える 1

0

OK、私は問題を見つけました

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

PUBLICを忘れていました:-(

    public class PaymentForm
    {
        public int id { get; set; }
        public string name { get; set; }
    }
于 2013-08-09T15:39:29.143 に答える