I am pretty new to coding. I am trying to define and store data from an API, but can't manage to define the values that exists nested in another object. Been looking around for a solution but the examples doesn't really work for me.
This is a part of the code:
for (var i in json) {
var TestOrdersXML = <testOrders _key="@testOrderId" operation="insertOrUpdate"/>;
if (json[i].testOrderId != undefined) TestOrdersXML.@testOrderId = json[i].testOrderId;
if (json[i].customerId != undefined) TestOrdersXML.@customerId = json[i].customerId;
if (json[i].installationOrderData.state != undefined) TestOrdersXML.@state = json[i].installationOrderData.state;
logInfo(" Test order Id: " + json[i].testOrderId + " Customer Id: " + json[i].customerId + " STATE: " + json[i].state);
//collection.appendChild(TestOrdersXML);
}
The response I get from the log is: Test order Id: 123456 Customer Id: 123456 STATE: undefined.
This is the json I am trying to get:
[
{
"installationOrderData":{
"state": "booked"
},
"customerId": 123456,
"testOrderId": 123456
}
]
Thanks.
json[i].state, do you meanjson[i].installationOrderData.state?