离子无法发布嵌套数组

时间:2019-02-21 17:14:32

标签: javascript json typescript ionic-framework

我早些时候发布了following问题,看来我的API端点没有任何问题,并且错误出在客户端。我正在尝试将数据发布到上述API端点。

我正在如下构建JSON对象:

let data = {
      "deliveryStreet": this.formGroup.get('shippingLineOne').value,
      "deliveryBuilding": this.formGroup.get('shippingLineTwo').value,
      "deliveryCity": this.formGroup.get('shippingCity').value,
      "deliveryProvince": this.formGroup.get('shippingProvince').value,
      "deliveryPostalCode": this.formGroup.get('shippingPostalCode').value,
      "cardName": this.formGroup.get('cardholderName').value,
      "cardNumber": this.formGroup.get('ccNum').value,
      "cardExpiry": this.formGroup.get('ccExp').value,
      "cardCvv": this.formGroup.get('cardCvv').value,
      "orderItems": this.cart.cartItems
    };

this.cart.cartItems是对象数组。在JSON.stringify之前,我尝试过直接POST既对数组又对整个对象进行对策,但这没有什么区别。当我删除"orderItems": this.cart.cartItems时,POST成功了,所以我知道它与数组有关。

我正在POST中对数据进行如下操作:

//Set serializer
this.http.setDataSerializer('JSON');
this.http.setSSLCertMode('nocheck');

//Call the endpoint
let response = await this.http.post(`${API}/${endpoint}`, data, { 'Authorization': bearer });

有人知道为什么我不能在我的JSON对象中POST的orderItems数组吗?

0 个答案:

没有答案