×
Good News Everybody!
The new search engine is LIVE!
Please report any problems to david (at) midrange.com.
Hi All,
I'm trying to parse a simple json document using yajl. Here is the code I
have.
dcl-proc GetCurrency ;
dcl-pi *n char(52);
pJson char(32766);
end-pi;
dcl-s i int(10);
dcl-s j int(10);
dcl-s docNode like(yajl_val);
dcl-s node like(yajl_val);
dcl-s val like(yajl_val);
dcl-s rates like(yajl_val);
dcl-s errMsg varChar(500);
dcl-s key varChar(50);
dcl-s retMsg like(msg);
// In debug pJson = {"success":true,
"timestamp":1580953386,
"base":"EUR",
"date": "2020-02-06",
"rates":{"USD":1.099578,"CAD":1.460943}}
docNode = yajl_string_load_tree(pJson :errMsg);
If errMsg <> *blanks;
Return *blanks;
Endif;
node = yajl_object_find(docNode :'base');
errMsg = yajl_get_string(node);
// In debug errMsg = 'EUR'
rates = yajl_object_find(docNode :'rates');
i = 0;
Dow yajl_array_loop(rates :i :node);
// In debug this loop is never entered so yajl_array_loop is returning
false
j = 0;
Dow yajl_object_loop(node :j :key :val);
If key = 'USD';
retMsg = 'Rate for USD = ' + yajl_get_string(val);
Leave;
Endif;
If retMsg <> *blanks;
Leave;
Endif;
Enddo;
Enddo;
yajl_tree_free(docNode);
Return retMsg;
end-proc;
In debug I can see that I am able to find the node 'base' but I am unable
to find the node 'rates'.
Can anyone see what I'm missing?
Thanks,
Rob
As an Amazon Associate we earn from qualifying purchases.
Follow-Ups :
This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page . If you have questions about this, please contact
[javascript protected email address] .
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.