Skip to main content

Hey, i'm trying to convert a (complexe) uniface associative list into a struct. I found some samples on this forum but i'm encoutering some problems.

this 'debug' screen shows the result after the struct->$name (1) instruction.

 As you can see in the results (2) the node did not accept the name, nore did we get any error.

I tried to simulate the procedure via a test-form and (obviously) here we donnot encouter any problems (see attachment)

Anyone?

Thanks in advance,

Geert



------------------------------
Geert Dupont
Zorgi NV
Mechelen BE
------------------------------

Hey, i'm trying to convert a (complexe) uniface associative list into a struct. I found some samples on this forum but i'm encoutering some problems.

this 'debug' screen shows the result after the struct->$name (1) instruction.

 As you can see in the results (2) the node did not accept the name, nore did we get any error.

I tried to simulate the procedure via a test-form and (obviously) here we donnot encouter any problems (see attachment)

Anyone?

Thanks in advance,

Geert



------------------------------
Geert Dupont
Zorgi NV
Mechelen BE
------------------------------

Does $name work on scalar nodes? Vnode has just been assigned a scalar value (VVAL). 

You might be better off with vnode->"%%vid%%%" = vval. 

Regards, 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Jonas Metals Software Limited
Sheffield GB
------------------------------

Does $name work on scalar nodes? Vnode has just been assigned a scalar value (VVAL). 

You might be better off with vnode->"%%vid%%%" = vval. 

Regards, 

Iain



------------------------------
Iain Sharp
Head of Technical Services
Jonas Metals Software Limited
Sheffield GB
------------------------------

Iain,

Thanks for the response.

I succeeded at solving my problem with your suggestion:

;-------------------------------------------------------------------------------
function lfn_List2Struct4Json
returns struct
params
string pList : IN
boolean isIndexed : OUT ; indication of indexed list (array)
endparams
variables
string vItem , vId , vVal , vVal0
numeric vIndx
struct  vStruct, vNode
endvariables
isIndexed = 'F'
vStruct = $newstruct
forlist/id vId, vVal , vIndx in pList
if (vId != "")
if (($itemcount(vVal) > 1 & vId != vVal) | $idpart(vVal) != $valuepart(vVal))
; embedded struct, recursive call
vNode = $newstruct
vNode -> "%%vId" = lfn_list2Struct4Json(vVal,isIndexed)
if (isIndexed) vNode->"%%vId"->$tags->JsonClass="array"
else
if (vId != vVal)
vNode=$newstruct
vNode->"%%vId" = vVal
else
vNode->*{vIndx} = vVal
endif
endif
vNode->$parent = vStruct
endif
endfor
return vStruct
end ; lfn_List2Struct4Json


------------------------------
Geert Dupont
Zorgi NV
Mechelen BE
------------------------------