We are using Netweaver Gateway to get data from SAP. I have a class which I use with JsonConvert.DeserializeObject<ODataObject> to get the JSON converted to my model. Which works fine.
But now we are working with HEADERS and ITEMS.
Can't get it converted to a (nested) model.
I got this JSON return from Netweaver Gateway:
{
"d": {
"__metadata": {
"id": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_hdrSet('1')",
"uri": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_hdrSet('1')",
"type": "ZLOTO_POC_SRV.WorkPermit_hdr"
},
"WpNr": "1",
"WoNr": "123456789",
"Desc1": "FLOP12",
"Desc2": "No ieda",
"Loc1": "",
"Loc2": "",
"Execution": "I",
"ExecDept": "'t smoorkot",
"ExecComp": "",
"SupExec": "Big boss",
"SupExecTel": "+32474895623",
"VpkInstr": "Mr unknown",
"VpkInstrTel": "+32474895624",
"WorkSup": "N/A",
"WorkSupTel": "+32474895625",
"Status": "",
"ValidFrom": null,
"ValidTo": null,
"CreateUser": "",
"ChangeUser": "",
"WorkPermit_hdr_itm_nav": {
"results": [{
"__metadata": {
"id": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_itmSet(WpNr='1',WoOper='00000001')",
"uri": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_itmSet(WpNr='1',WoOper='00000001')",
"type": "ZLOTO_POC_SRV.WorkPermit_itm"
},
"WpNr": "1",
"WoOper": "00000001",
"Desc": "First iitem desc",
"CreateUser": "TDPO",
"ChangeUser": "TDPO"
}, {
"__metadata": {
"id": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_itmSet(WpNr='1',WoOper='00000002')",
"uri": "http://xxx:8000/sap/opu/odata/sap/ZLOTO_POC_SRV/WorkPermit_itmSet(WpNr='1',WoOper='00000002')",
"type": "ZLOTO_POC_SRV.WorkPermit_itm"
},
"WpNr": "1",
"WoOper": "00000002",
"Desc": "Second item description",
"CreateUser": "TDPO",
"ChangeUser": "TDPO"
}]
}
}
}
I believe you might have to look at your models, for they might need to be updated to handle the structures.
For it took me a few tries but there seems to be a redundancy in the model; as I named it,
Result
. For once I made that class have all possible properties, it became the go-to class for both levels; it then deserialized.Here is my deserialization line:
Models
Test JSON