YAJL_OBJECT_LOOP not working on second level group
Posted: Wed Aug 13, 2025 7:35 pm
The YAJL_OBJECT_LOOP the body element works fine but does not work for the return_message element inside the body.
The YAJL_OBJECT_LOOP for the return_message returns nothing. The return_message pointer is not null.
The items pointer works fine in a YAJL_ARRAY_LOOP (not shown).
The YAJL_OBJECT_LOOP for the return_message returns nothing. The return_message pointer is not null.
The items pointer works fine in a YAJL_ARRAY_LOOP (not shown).
Code: Select all
{
"statusCode": 200,
"body": {
"return_message": [
{
"message_long_text": "Order: 10014027 created.",
"message_severity": 0,
"message_text": "success",
"msgid": "STS0001"
}
],
"items": [
{
"item_id": "1",
"mfr_code": "ACI",
"part_number": "172189",
"list": 29.51,
"sell": 13.82,
"core": 0,
"quantity_ordered": 1,
"status": "success"
},
{
"item_id": "2",
"mfr_code": "FFH",
"part_number": "PG2500F",
"list": 7.79,
"sell": 2.11,
"core": 0,
"quantity_ordered": 1,
"status": "success"
}
],
"order_number": "10014027",
"legacy_order_number": "38806743",
"status": "success"
}
}
Code: Select all
docNode = YAJL_stmf_load_tree( JSON_Response : JSON_errMsg );
body = YAJL_object_find(docNode: 'body');
idx = 0;
dow YAJL_object_loop(body : idx : keytext : elem) ;
select ;
when keytext = 'status';
status = yajl_get_string(elem);
when keytext = 'error_description';
error_description = yajl_get_string(elem);
when keytext = 'return_message';
return_message = elem;
when keytext = 'items';
items = elem;
endsl;
enddo;
idx = 0;
dow YAJL_object_loop(return_message : idx : keytext : elem) ;
select ;
when keytext = 'message_long_text';
message_long_text = yajl_get_string(elem);
when keytext = 'message_severity';
message_severity = YAJL_get_number(elem);
when keytext = 'message_text';
message_text = yajl_get_string(elem);
when keytext = 'msgid';
msgid = yajl_get_string(elem);
other;
endsl;
enddo;