[SOLVED] JSONTOSTRUCT

Author: fearandir@gmail.com (fearandir)

Hello.   We are dealing with a restful ws that returns a JSON object. I am trying to transform the JSON to a STRUCT sctructure but, with no success.... variables STRING vs_url, vs_head, vs_boby, vs_resp STRUCT VST_STRUCT, vst_struct1, vst_struct2, vst_struct3 endvariables vs_url = "http://services.groupkt.com/country/get/iso2code/ES" activate "UHTTP".Send(VS_URL, "GET" , " " , " " , vs_head, vs_boby, vs_resp) if (VCBODY!="") jsonToStruct VST_STRUCT VCBODY message $procReturnContext message $STATUS message VST_STRUCT vst_struct1 = VST_STRUCT{"id"} endif   In debugging i see this:  if (VCBODY!="") ...   done done   message $procReturnContext     message $STATUS     message VST_STRUCT     vst_struct1 = VST_STRUCT{"id"} endif   So...How am I wrong ?   Thanks in advance, Sergio

5 Comments

  1. Hi Sergio, In case you want to "print" a Struct then you need to use either the Struct Function $dbgString or $dbgStringPlain. E.g. > putmess VST_STRUCT->$dbgString > Output:

    []
            [$tags]
                    [jsonClass] = object
            [RestResponse]
                    [$tags]
                            [jsonClass] = object
                    [messages]
                            [$tags]
                                    [jsonClass] = array
                            [] = "More webservices are available at http://www.groupkt.com/post/f2129b88/services.htm"
                                    [$tags]
                                            [jsonDataType] = string
                            [] = "Country found matching code [ES]."
                                    [$tags]
                                            [jsonDataType] = string
                    [result]
                            [$tags]
                                    [jsonClass] = object
                            [name] = "Spain"
                                    [$tags]
                                            [jsonDataType] = string
                            [alpha2_code] = "ES"
                                    [$tags]
                                            [jsonDataType] = string
                            [alpha3_code] = "ESP"
                                    [$tags]
                                            [jsonDataType] = string
    

      I, however, do not understand what you would like to achieve with this assignment: > vst_struct1 = VST_STRUCT{“id”} What do you want to do here? Hope this helps. Kind regards, Daniel Iseli Uniface Support


    Author: diseli (daniel.iseli@uniface.com)
  2. Hi Daniel, You can forget about that line. I am not familiar with STRUCTS management rigth now. The problem is the  jasontostruct proc statement do not work inside my client uniface app.    debugging, where  the jsontostruct statment  should appear appears instead : ... done done Could be a ASN, USYS configuration files problem?   I am using Uniface 9.6.04   Thanks   Sergio


    Author: fearandir (fearandir@gmail.com)
  3. Hi Sergio, Thanks for the info. But in case you don't see the jsonToStruct statement in the Debugger and instead ".." then I somehow have my doubts that you are actually using version 9.6.04. Could you please double check this? You could run your client app with /pri=64 (or $iopprint=64) and check the log file if all the loaded Uniface DLL's actually show as version number 9.6.04 (or higher). Hope this helps. Kind regards, Daniel


    Author: diseli (daniel.iseli@uniface.com)
  4. oooook.   Someone from the IT systems team gonna know my wrath... We migrated recently to Windows 7 and this is the consequence...   [startup] Uniface   : [MSW] 9.6.03.01,  (Aug 26 2013), $ioprint=127   Thank you very much.    Sergio


    Author: fearandir (fearandir@gmail.com)
  5. Thanks Sergio. It's good to hear that you could find the source of the problem. Smile And if you have any further questions concerning jsonToStruct then let us know. Wink Daniel


    Author: diseli (daniel.iseli@uniface.com)