マイサービス角度のHTTP POSTは、複雑なオブジェクトを送信
public submitBooking(createBooking: CreateBooking) { const body = this.getSaveBookingRequestBody(createBooking); //const json = JSON.Stringify(body) //It throws 415 error return this.httpClient.post(this.baseUrl + 'Save', body) .subscribe(); } private getSaveBookingRequestBody(createBooking: CreateBooking): any { const body = { 'Booking': { 'Header': this.getBookingHeader(createBooking), //It works fine. 'Items': [this.getBookingItems(createBooking)], }, 'TestOnly': !environment.production, }; this.Logger.log(body); return body; } private getBookingItems(createBooking: CreateBooking): any { const bookingItem = { 'CountryOfOrigin': createBooking.booking.countryoforigin, 'VehicleValue': createBooking.booking.valueofvechicle, 'SerialNumber': createBooking.booking.bookingNumber, 'Description': createBooking.booking.description, 'Mobility': createBooking.booking.mobility, 'Currency': createBooking.booking.currency, 'Weight': createBooking.booking.weight, 'Year': createBooking.booking.year, 'Cbm': createBooking.booking.cbm, //This is an array it doesn't work. 'SubUnits':[ createBooking.booking.relatedVehicles.forEach(element => { const units = { 'RelationType': element.relation, 'Weight': element.weight, 'Year': element.year, }; })], }; return bookingItem;
私は、Web APIで
。 配列をループして本文として送信するオブジェクトを作成する方法。SubUnits
常に空のPOST本体を作成
マイ角度モデルとWEB-APIオブジェクトは、私もJSON.Stringify(unitsArray)
とを試してみました
異なるサブユニット
に戻すconst unitsArray = [];
createBooking.booking.relatedVehicles.forEach(element => {
const units = {
'RelationType': element.relation,
'SerialNumber': element.chassisno,
'Weight': element.weight,
'Year': element.year,
};
unitsArray.push(units);
});
SubUnits : JSON.stringify(unitsArray); // It also doesn't work with API.
バージョン: 角5 活字体2.4。 2
別の方法では、foreach単位が割り当てられました。しかし、あなたの 'マップ'は正常に動作しています。どうもありがとう。 – Eldho