У меня есть приложение angular, которое отправляет массив объектов и сервер API. NET.
Проблема в том, что my. NET получает данные, но не может их привязать к объекты правильно.
Angular Приложение внешнего интерфейса:
data: IAccountBookKeeping[] = [];
onClickSendToAPI(){
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
}
const stringify = fastJson({
type: 'object',
properties: {
AccountingDate: {
type: 'string'
},
RegistrationNo: {
type: 'string'
},
Currency: {
type: 'string'
},
IDKT: {
type: 'string'
},
OriginalIDKT: {
type: 'string'
},
CounterAccountIDKT: {
type: 'string'
},
ProjectCode: {
type: 'string'
},
Balance: {
type: 'string'
},
Text: {
type: 'string'
}
}
})
const jsonString: string[] = [];
this.data.forEach(element => {
jsonString.push(stringify(this.data[0]));
});
this.http.post('http://localhost:5000/api/GFSAccount',
JSON.stringify(jsonString),
httpOptions).subscribe(reponse =>
console.log(reponse));
}
Что Angular Передача интерфейса в API
["{\ "AccountingDate \": \ "20171130 \", \ "RegistrationNo \": \ "39A1 \", \ "Валютная \": \ "DKK \", \ "IDKT \": \ "34HS991016 \", \ "OriginalIDKT \ ": \" тест \», \ "CounterAccountIDKT \": \ "34HS980876 \", \ "ProjectCode \": \ "078 \", \ "Баланс \": \ "1 \", \ "Текст \" : \ "006-Hest prov-Ytd NOV17 \"} "," {\ "AccountingDate \": \ "20171130 \", \ "RegistrationNo \": \ "39A1 \", \ "Валюта \": \ "DKK \», \ "IDKT \": \ "34HS991016 \", \ "OriginalIDKT \": \ "тест \", \ "CounterAccountIDKT \": \ "34HS980876 \", \ "ProjectCode \": \ "078 \" , \ "Balance \": \ "1 \", \ "Text \": \ "006-Hest prov-Ytd NOV17 \"} "
ASP. NET Сервер получения API
[HttpPost]
public IActionResult Post([FromBody] IEnumerable<AccountBookKeeping> request)
{
return Ok(request);
}
ASP. NET AccountBookKeeping Class
public class AccountBookKeeping
{
public string AccountingDate { get; set; }
public string RegistrationNo { get; set; }
public string IDKT { get; set; }
public string OriginalIDKT { get; set; }
public string CounterAccountIDKT { get; set; }
public string Text { get; set; }
public string ProjectCode { get; set; }
public string Currency { get; set; }
public string Balance { get; set; }
}