1
0
-1

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?

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      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

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Robert,

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

        Gianni


          CommentAdd your comment...