如何在ionic 3中的REST API中发布数组

时间:2019-04-16 10:20:44

标签: angular ionic-framework ionic3 angular-http

我需要将数据发送到Rest API。数据采用数组格式。

enter image description here

上图中的

数据显示为[object object]。实际数据是上面的选项。

public optntocart(produc_id, countid, optionsselect) {

    let optionslt = optionsselect[3];

    console.log("3: "+optionslt);
    let localaccesstoken = localStorage.getItem('token');
    let apiUrl = this.urlService.apiUrl  + 'cart';
    let headers = new Headers({'Content-Type' : 'application/x-www-form-urlencoded'});
    let options = new RequestOptions({headers: headers});

    let postcredn = "access_token="+localaccesstoken+"&product_id="+produc_id+"&product_qty="+countid+"&product_option="+optionsselect;

    console.log(postcredn);

      return new Promise((resolve, reject) => {
          this.http.post(apiUrl, postcredn, options)

           .subscribe(res => {
            resolve(JSON.parse(JSON.stringify(res)));

           }, (err) => {
             reject(err);
           });
     });
    }

当我尝试邮递员时:

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试:

let postcredn = "access_token="+localaccesstoken+"&product_id="+produc_id+"&product_qty="+countid+"&product_option="+JSON.stringfy(optionsselect);

字符串化 product_option 值。