Uniface User Forum

 View Only
  • 1.  How to create a list with struct for a json in Uniface

    PARTNER
    Posted 12-09-2021 08:43
    Edited by Private Private 12-10-2021 08:00

    Hello everybody,

    i need to create a json with the programming language uniface. I use a struct to create the json. But i have a problem to create a list with a struct.

    See here my example for the list "Children".

    Example - JSON:

    {
        "First Name" : "Barbara",
        "Last Name" :  "Singh",
        "Date of birth" :   { "year" : 1955, "month" : 1, "day" : 23 }, 
        "Married" : true,
        "Children" :  
        [
            {  "Name" : "Martin", "Year of birth" :  1980 },
            {  "Name" : "Margaret", "Year of birth" : 1983 }        
        ],
        "Mobile phone" : null
    } 
    

    Example - Struct:

    []
        [First Name] = "Barbara"
        [Last Name]  = "Singh"
        [Date of birth]
            [year] = 1732             
            [month] = 2               
            [day] = 22                
        [Married] = "T"               
        [Children]
            []
                 [Name] = "Martin"
                 [Year of birth] = 1980      
            []
                 [Name] = "Margaret"   
                 [Year of birth] = 1983      
         [Mobile phone] 
    

    Example based on the Uniface documentation: Structs for JSON Data

    So, how can i create a list with uniface for a json?



    ------------------------------
    Viktor Kuenstler
    Abrechnungszentrum Emmendingen
    ------------------------------


  • 2.  RE: How to create a list with struct for a json in Uniface

    PARTNER
    Posted 12-09-2021 09:35
    Hello Viktor,

    You must define children as array  :  struct->Children->$tags->jsonClass="array"

    Gilles.

    ------------------------------
    Hortion Gilles
    Agfa-Gevaert NV
    ------------------------------



  • 3.  RE: How to create a list with struct for a json in Uniface

    PARTNER
    Posted 12-10-2021 02:26
    Thank you Gilles, it's works :)

    ------------------------------
    Viktor Kuenstler
    ARZ Haan AG
    ------------------------------



  • 4.  RE: How to create a list with struct for a json in Uniface

    Posted 12-10-2021 07:49
    Hi Viktor,

    if you know the result (your JSON) do the reverse way.

    jsontostruct V_STRUCT, V_JSON
    putmess V_STRUCT->$dbgString

    Now you can compare your struct with the result created by uniface.


    Regards
    Norbert

    ------------------------------
    Norbert Lauterbach
    Infraserv Gmbh & Co. Höchst Kg
    Frankfurt DE
    ------------------------------



  • 5.  RE: How to create a list with struct for a json in Uniface

    PARTNER
    Posted 12-10-2021 07:59
    Hi Norbert,

    thanks for your advice. This could help me with other json problems.

    ------------------------------
    Viktor Kuenstler
    ARZ Haan AG
    ------------------------------