我需要将数据发送到Rest API。数据采用数组格式。
上图中的数据显示为[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);
});
});
}
当我尝试邮递员时:
答案 0 :(得分:0)
尝试:
let postcredn = "access_token="+localaccesstoken+"&product_id="+produc_id+"&product_qty="+countid+"&product_option="+JSON.stringfy(optionsselect);
字符串化 product_option 值。