[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Reading JSON using YAJL
I'm not familiar with JSON and having difficulties reading the array
data form JSON file using YAJL. I use HTTPAPI to post JSON transaction
and receive the JSON result file into the IFS. I'm able to parse the
results JSON file for the object data, but when I try to extract the
JSON array data I run into issues. There are no errors, just null
values are returned for the array data. Any and all suggestions are
appreciated.
Below is the JSON I'm trying to read. I can read the JSONN object data
MessageID, MessageType, MessageTime, ApiVersion, but when I get to
Payload I get null values.
· "MessageId":"780f064a-4060-4197-a8d7-fa4c6fa8dbf0",
· "MessageType":"LoadLocation",
· "MessageTime":"2016-11-04T14:46:02.3266448+00:00",
· "ApiVersion":"1.1",
· "Payload":{
o "ResponseMessages":[
1. {
§ "Msg":"Message Received and Queued for
Processing.",
§ "Severity":"INFORMATION"
§ }
o ]
· }
· }
Here is how I defined the JSON data in my program:
D list_t ds qualified
D template
D msg 500a varying
D msgsev 500a varying
D result ds qualified
D msgid 500a varying
D msgtype 500a varying
D msgtime 500a varying
D apiver 500a varying
D objname 500a varying
D list likeds(list_t) dim(999)
Here is how I try to read the JSON data in my program:
docNode = yajl_stmf_load_tree( '/kbxws/result.json' : errMsg
);
if errMsg <> '';
// handle error
endif;
node = YAJL_object_find(docNode: 'MessageId');
result.msgid = YAJL_get_string(node);
node = YAJL_object_find(docNode: 'MessageType');
result.msgtype = YAJL_get_string(node);
node = YAJL_object_find(docNode: 'MessageTime');
result.msgtime = YAJL_get_string(node);
node = YAJL_object_find(docNode: 'ApiVersion');
result.apiver = YAJL_get_string(node);
node = YAJL_object_find(docNode: 'Payload');
result.objname = YAJL_get_string(node);
list = YAJL_object_find(docNode: 'ResponseMessages');
i = 0;
dow YAJL_ARRAY_LOOP( list: i: node );
lastElem = i;
val = YAJL_object_find(node: 'Msg');
result.list(i).msg = yajl_get_string(val);
val = YAJL_object_find(node: 'Severity');
result.list(i).msgsev = yajl_get_string(val);
enddo;
yajl_tree_free(docNode);
*inlr = *on;
Doug Peterson
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------