× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Jan,

On 8/16/2016 10:37 AM, Jan Grove Vejlstrup wrote:
I know that I have a problem with the ccsid of the file. I think I can
solve this by getting a file that are coded correctly in UTF-8.

But I don't know how to cope with the node "MeasureUnit". This node
doesn't have a single value but a new JSON with several values.

I tried your JSON document. There were two errors in it that I had to fix, but after making those changes it worked perfectly for me.

1) Your document had extra * characters from when you tried to make it bold (you already know about this)

2) Your document was missing the colon (the : character) after the first "MeasureUnit"

Once I added these, it worked perfectly for me.

Here is the RPG program that I used for my test:

H DFTACTGRP(*NO) ACTGRP(*NEW) OPTION(*SRCSTMT)
H BNDDIR('YAJL')

/include yajl_h

D QUILNGTX PR ExtPgm('QSYS/QUILNGTX')
D text 500a const
D length 10i 0 const
D msgid 7a const
D qualmsgf 20a const
D errorCode 32767a options(*varsize)

D errorCode ds
D bytesProv 10i 0 inz(0)
D bytesAvail 10i 0 inz(0)

D MeasureUnit_t ds qualified template
D UnitDesc 10a
D UnitDescSht 4a
D UnitCode 2a
D UnitItemCnt 8p 1 inz(0)
D DecimalCount 7p 0 inz(0)

D SalesOrderItems_t...
D ds qualified template
D PositionsNo 1a
D ItemNo 8a
D MeasureUnit likeds(MeasureUnit_t)
D inz(*likeds)
D ItemDescrip 30a
D SortNo 10i 0 inz(0)
D TotalQty 11p 1 inz(0)
D QtyPicked 11p 1 inz(0)
D Location 8a
D isFloorItem 1n inz(*off)

D result ds qualified
D SalesOrderNo 6a
D PackageQty 7p 1 inz(0)
D PalletQty 7p 1 inz(0)
D Weight 8p 2 inz(0)
D OrderState 2p 0 inz(0)
D ItemCnt 10i 0 inz(0)
D Item likeds(SalesOrderItems_t)
D inz(*likeds) dim(999)

D i s 10i 0
D j s 10i 0
D k s 10i 0
D errMsg s 500a varying inz('')

D docNode s like(yajl_val)
D list s like(yajl_val)
D node s like(yajl_val)
D val s like(yajl_val)
D unitVal s like(yajl_val)
D items s like(yajl_val)
D key s 50a varying
D unitKey s 50a varying

/free
*inlr = *on;

docNode = yajl_stmf_load_tree( 'jgv_test.json' : errMsg );
if errMsg <> '';
QUILNGTX( errMsg: %len(errMsg): *blanks: *blanks: errorCode );
return;
endif;

i = 0;
dow YAJL_OBJECT_LOOP( docNode: i: key: val);

select;
when key = 'SalesOrderNo';
result.salesOrderNo = yajl_get_string(val);
when key = 'PackageQuantity';
result.packageQty = yajl_get_number(val);
when key = 'PalletQuantity';
result.palletQty = yajl_get_number(val);
when key = 'Weight';
result.weight = yajl_get_number(val);
when key = 'SalesOrderState';
result.orderState = yajl_get_number(val);
endsl;

enddo;

items = yajl_object_find(docNode: 'SalesOrderItems');
result.itemCnt = YAJL_ARRAY_SIZE(items);

i = 0;
dow YAJL_ARRAY_LOOP( items: i: node );

j = 0;
dow YAJL_OBJECT_LOOP( node: j: key: val);

select;
when key = 'PositionsNo';
result.item(i).positionsNo = yajl_get_string(val);
when key = 'ItemNo';
result.item(i).itemNo = yajl_get_string(val);
when key = 'ItemDescription';
result.item(i).itemDescrip = yajl_get_string(val);
when key = 'SortNo';
result.item(i).sortNo = yajl_get_number(val);
when key = 'TotalQuantity';
result.item(i).totalQty = yajl_get_number(val);
when key = 'QuantityPicked';
result.item(i).qtyPicked = yajl_get_number(val);
when key = 'StorageLocation';
result.item(i).location = yajl_get_string(val);
when key = 'IsFloorItem';
result.item(i).isFloorItem = yajl_is_true(val);
when key = 'MeasureUnit';

k = 0;
dow YAJL_OBJECT_LOOP( val: k: unitKey: unitVal );

select;
when unitKey = 'UnitDesc';
result.item(i).measureUnit.unitDesc =
yajl_get_string(unitVal);
when unitKey = 'UnitDescShort';
result.item(i).measureUnit.unitDescSht =
yajl_get_string(unitVal);
when unitKey = 'UnitCode';
result.item(i).measureUnit.unitCode =
yajl_get_string(unitVal);
when unitKey = 'UnitItemCount';
result.item(i).measureUnit.unitItemCnt =
yajl_get_number(unitVal);
when unitKey = 'DecimalCount';
result.item(i).measureUnit.decimalCount =
yajl_get_number(unitVal);
endsl;

enddo;

endsl;
enddo;

enddo;

yajl_tree_free(docNode);

// At this point in the program, the "Result" data structure
// contains all of the data from the JSON document.

/end-free

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.