Send/Receive data in JSON format

Author: alejandron@afsi.com (danieto)

Hello, I'm looking to build a prototype of a Uniface 9.6 Web component that will send and receive data in JSON format. Do any of you guys have an example of how to do this?, or some pointers of where should I how start? Thanks Alejandro

5 Comments

  1. Hi Alejandro, I'm not quite sure what you are after, so this is a more global hint: With your uniface installation you will have a samples directory with some webservice* examples which may help you. In the helpfile, and check the index for "tutorial" and you will see a couple of web related pages. Have a look in the helpfile and check the index for "javascript" and use the search function for "json" for further information. "webload" and "websave" already mention something about JSON as do "getproperties". With uniface, you can prepare javascript code inside uniface triggers as well so you will have at least one place where you can handle JSON structures with ease..


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. Hi Alejandro, It depends on what you exactly need to accomplish. Send/recieve: Here is an example of a very simple technique: http://theunifaceuniverse.blogspot.nl/2012/03/build-restful-webservice-in-3-lines-of.html Json: Most people use a struct and convert the content to (or from) Json. There is no statement for that yet in Uniface, but it is not so difficult to do it yourself in Proc code. Below is a bit of code for you as inspiration. It is not fully generic so you may need to tinker with it to get it to work in your situation. entry lpStructtojson params struct pStruct : INOUT string pJson : INOUT string pLevel : INOUT endparams variables string vElement, vValue, vIndent numeric vStructSize, vCounter, i struct vStructpart endvariables ; indentation for i = 1 to pLevel vIndent = $concat(vIndent, $string("&uTAB;")) endfor if (pJson = "") pJson = "{%%^" else pJson = $concat(pJson, " {%%^") endif vStructSize = pStruct->*->$collSize vCounter = 1 while (vCounter *{vCounter}->$name if (pStruct->*{vCounter}->$isleaf) ; vValue = pStruct->*{vCounter} pJson = $concat(pJson, vIndent, "%%"", vElement, "%%": ") pJson = $concat(pJson, "%%"", vValue, "%%"") if (pStruct->*{vCounter+1}->$isleaf) pJson = $concat(pJson, ",%%^") else pJson = $concat(pJson, "%%^") endif else ; pJson = $concat(pJson, vIndent, "%%"", vElement, "%%":") vStructpart = pStruct->*{vCounter} pLevel += 1 call lpStructtoJson(vStructpart,pJson, pLevel) pLevel -= 1 pJson = $concat(pJson, vIndent, "}%%^") endif vCounter += 1 endwhile if (pLevel = 0) pJson = $concat(pJson, "}%%^") endif end


    Author: Theo Neeskens (tneeskens@itblockz.nl)
  3. Grrr, all indentation is gone....


    Author: Theo Neeskens (tneeskens@itblockz.nl)
  4. Hi Theo, you have all my sympathy on that. It's a shame when any formatting effort is lost. and instead of a nice and readable text you got the above result. Hopefully we may get an upgraded editor window which keeps formatting and liberates us from the <GOLD>; burden.


    Author: ulrich-merkel (ulrichmerkel@web.de)
  5. Thank you all for your reply.


    Author: danieto (alejandron@afsi.com)