[英]ASP .Net Framework API gets empty objects
我有一個帶有 RezeptController 的RezeptController
,因為我有Put
和Post
函數,這些函數在 Angular 工具中可以正常工作。 在我的 C# 工具中,它以類似的方式工作,我試圖像這樣發布我的 object:
public async Task UpdateRezept(Rezept rezept)
{
HttpResponseMessage response = await client.PutAsJsonAsync(
rezeptUrl + "/" + rezept.id, rezept);
response.EnsureSuccessStatusCode();
}
當我查看 object 時,一切看起來都很棒,但在我的 API 中,它看起來像這樣:
public void Put(int id, [FromBody] Rezept iRezept)
{
SerializerService serializerService = new SerializerService();
string stringifiedObject = serializerService.getXml(typeof(Rezept), iRezept);
SharepointService ss = new SharepointService();
ss.UpdateList(id, stringifiedObject);
}
只是一個空的 shell。 Output 看起來像這樣:
<?xml version="1.0" encoding="utf-16"?>
<Rezept xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id>0</id>
<ausstelldatum xsi:nil="true" />
<isGebFrei>false</isGebFrei>
<isGebPfl>false</isGebPfl>
<isNoctu>false</isNoctu>
<isSonstige>false</isSonstige>
<isUnfall>false</isUnfall>
<isArbeitsunfall>false</isArbeitsunfall>
<unfalldatum xsi:nil="true" />
</Rezept>
而我的應用程序中的 JSON 看起來像這樣:
{
"Zuzahlung": 22.595813239527445,
"GesamtBrutto": 217.85619214798743,
"IsValid": true,
"kunde": {
"IsValid": true,
"vorname": "test",
"name": "test",
"strasse": "test",
"ort": "test",
"plz": "12345",
"versichertennummer": "K987456321",
"versichertenstatus1": {
"kennung": 1,
"name": "Mitglied"
},
"versichertenstatus2": {
"kennung": 0,
"name": "Keine besondere Personengruppe"
},
"versichertenstatus3": {
"kennung": 0,
"name": "Kein DMP"
},
"gebDatum": "1998-03-25T00:00:00"
},
"ausstelldatum": "2022-08-01T00:00:00",
"arzt": {
"IsValid": true,
"betriebsstaettennummer": "963258741",
"lanr": "963258741"
},
"medikament1": {
"name": "Ibuprofen 800 Ratiopharm",
"taxe": 93.400614110045723,
"pzn": null,
"autIdem": true
},
"medikament2": {
"name": "adwrewfdsfsd",
"taxe": 82.55751828522871,
"pzn": null,
"autIdem": true
},
"medikament3": {
"name": "dsgsdgfg",
"taxe": 41.898059752712982,
"pzn": null,
"autIdem": false
},
"isGebFrei": false,
"isGebPfl": true,
"isNoctu": false,
"isSonstige": false,
"isUnfall": false,
"isArbeitsunfall": false,
"unfalldatum": null,
"arbeitgeber": null,
"id": 45,
"title": "Rezept 45",
"krankenkasse": {
"name": "AOK Baden Württemberg",
"kennung": "108018132"
}
}
我的 API 中的 Model 看起來像這樣:
[Serializable]
public class Rezept
{
public Krankenkasse krankenkasse;
public int id;
public string title;
public Kunde kunde;
public DateTime? ausstelldatum;
public Arzt arzt;
public Medikament medikament1;
public Medikament medikament2;
public Medikament medikament3;
public bool isGebFrei;
public bool isGebPfl;
public bool isNoctu;
public bool isSonstige;
public bool isUnfall;
public bool isArbeitsunfall;
public DateTime? unfalldatum;
public string arbeitgeber;
public Rezept()
{
}
}
你們看到我的錯誤了嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.