Hello...
Trying to access or parse nested objects/arrays from JSON output but can't seem to get passed one frustrating hurdle.. I've seen a similar posting on this but doesn't quite address my issue. Any help would be appreciated. For the record, I am a newbie. Thx.
Here's the JSON output I'm trying to access. The Objects I'm looking to enumerate in the arrays are "dataPage":"data":"name": and "dataPage":"data":"backing":"switch Obj": "objectID": I am not searching on any specific object numeric value either (I am merely trying to locate unique virtual wire names to continue building further upon in my script. : (Note formatting may be offset).
{
"dataPage": {
"pagingInfo": {
"pageSize": 20,
"startIndex": 0,
"totalCount": 24,
"sortOrderAscending": true
},
"data": [
{
"objectId": "virtualwire-1",
"objectTypeName": "VirtualWire",
"name": "Transit-Network",
"backing": [
{
"switch Obj": {
"objectId": "dvs-28",
},
}
]
},
{
"objectId": "virtualwire-2",
"objectTypeName": "VirtualWire",
"name": "Web-Tier",
"backing": [
{
"switchObj": {
"objectId": "dvs-28",
},
},
]
{
"objectId": "virtualwire-3",
"objectTypeName": "VirtualWire",
"name": "App-Tier",
"backing": [
{
"switchObj": {
"objectId": "dvs-28",
},
}
]
}
]
Here's the code I'm using: Error I'm getting is "Error in (Workflow:Find One TIE Gateway / Parse JSON (item1)#56) TypeError: Cannot read property "data" from undefined
var theType = "GET";
operationUrl = "/2.0/vdn/virtualwires/"
//Set up and make request/PUT
var request = restHost.createRequest(theType, operationUrl, "");
request.setHeader("Content-Type", "application/json; charset=UTF-8");
request.setHeader("Accept", "application/json");
//Log the URL
System.log("request: " + request.fullUrl);
var response = request.execute();
//log the JSON response
System.log("vdn response: " + response.contentAsString);
var wiresObject = response.contentAsString;
var items = wiresObject.dataPage.data ("Error in (Workflow:Find One TIE Gateway / Parse JSON (item1)#56) )
//System.log("Items Output :" + items);
//Create Virtual Wire Index based on vWire Name
var theWireIndex;
for (i = 0; i < items.length; i++) {
var strName = items[i].name
//System.log(strName)
if (strName.indexOf(nameToFind + "-vWire") > -1) {
//System.log('the index with the string is: ' + i);
theWireIndex = i;
}
}