Skip to main content

I have a tree list which describes a multi level navigation tree, I want to convert it to an JSON string to use in a JQuery menu. I thought I could do this via a struct.

How can I get a list into a struct so I can convert to JSON?

I have a tree list which describes a multi level navigation tree, I want to convert it to an JSON string to use in a JQuery menu. I thought I could do this via a struct.

How can I get a list into a struct so I can convert to JSON?

Hi Robert,

Why NOT building directly a struct while reading database with another operation?

Gianni



I have a tree list which describes a multi level navigation tree, I want to convert it to an JSON string to use in a JQuery menu. I thought I could do this via a struct.

How can I get a list into a struct so I can convert to JSON?

Not perfect, but that could be a good start:

entry list2struct
    returns struct
params
    string pListe : in
endparams
variables
    struct vStruct, vNode
    string vId, vVal
endvariables

    vStruct = $newstruct
    forlist/id vId, vVal in pListe
        if (vId != "")
            if ($itemcount(vVal) > 1 & vId != vVal)
                ; embedded struct, recursive call
                vNode = list2struct(vVal)
            else
                vNode = vVal
            endif
            if (vId != vVal)
                vNode->$name = vId
            endif
            vNode->$parent = vStruct
        endif
    endfor
    return vStruct

end

Kind regards,

Richard