New to RPG and I'm a little lost on how to do this. "data" is an array with info I need, I am able to parse this. However "cargoLoaded" is an array inside the "data" array which contains a single item "cargoSensor1". I need the value of cargoSensor1.
JSON and a portion of my code below (data areas not included).
JSON I want to parse (I need the value cargoSensor1)
{
"success": true,
"data": [
{
"address": "6061 Segale Park Dr C",
"cargoLoaded": [{"cargoSensor1": false}],
"city": "Tukwila",
"deviceId": 10841293,
"eventDateTime": "2020-03-02 17:27:56",
"eventTypeName": "Cargo Update",
"gpsTrackedDistance": 3.029E7,
"heading": 294,
"id": 14364709,
"idle": false,
"idleStartTime": null,
"ignitionOn": false,
"ignitionOnStartTime": null,
"inputs": ["ATIS Inactive"],
"landmarkId": null,
"landmarkName": null,
"lat": 47.434048,
"lng": -122.258198,
"moving": false,
"movingStartTime": null,
"name": "1823U",
"serial": "BK2007237851",
"speed": 0,
"state": "WA",
"stopped": true,
"stoppedStartTime": "2020-02-25 17:20:31",
"tractorId": null,
"tractorName": null,
"tractorPower": false,
"tractorPowerStartTime": "",
"typeId": 3,
"typeName": "Trailer",
"zip": "98188"
},
*
/Free
docNode = yajl_stmf_load_tree('/home/smid/D#status.txt' :ErrMsg);
If ErrMsg = '';
list = yajl_object_find( docNode: 'data');
i=0;
DoW YAJL_ARRAY_LOOP(list: i: node);
//get trailer number from name value-works
val = yajl_object_find(node: 'name');
valName = yajl_get_string(val);
dsply valName;
exsr FMT_TLR_KEY;
dsply @TLR1;
//Atempt to get cargoSensor data-dont work
val = yajl_object_find(node: 'cargoSensor1');
valCarg = yajl_is_true(val);
dsply valCarg;
exsr UPD_TLR;
exsr UPD_SAT_TLR;
EndDo;
EndIf;
yajl_tree_free(docNode);
*inlr = *on;
/End-Free
You should be accessing the cargoLoaded
array just like you accessed the data
array:
/Free
docNode = yajl_stmf_load_tree('/home/smid/D#status.txt' :ErrMsg);
If ErrMsg = '';
list = yajl_object_find( docNode: 'data');
i=0;
DoW YAJL_ARRAY_LOOP(list: i: node);
//get trailer number from name value-works
val = yajl_object_find(node: 'name');
valName = yajl_get_string(val);
dsply valName;
exsr FMT_TLR_KEY;
dsply @TLR1;
//UPDATED CODE BLOCK HERE
cargoList = yajl_object_find(node: 'cargoLoaded');
DoW YAJL_ARRAY_LOOP(cargoList: j: node);
val = yajl_object_find(node: 'cargoSensor1');
valCarg = yajl_get_string(val);
dsply valCarg;
exsr UPD_TLR;
exsr UPD_SAT_TLR;
EndDo;
EndDo;
EndIf;
yajl_tree_free(docNode);
*inlr = *on;
/End-Free