Uniface web tools - uList2json
Here come a little tool that transforms your simply Uniface associative list into a JSON string.
The basic idea behind this is just to make your list accessable in an easy way for your server page. First of all, let me show you the code.
Notes on this codeThis code is surely not the final cast. Take care of the valueparts, as the could need to get quoted in order not to destroy the JSON structure.
Further the code could be used recursively if somebody would like to take hands on that.
ExampleA code is a code, but it gains more acceptance with an example. We will take a little case on this. Straight from my development here, the scenario is that a server page (the HTML in the browser) expects data in a JSON string (delivered by Uniface). But as the Uniface code encounters an error while running through the statements, we will deliver a failure notice to the requesting page. Take a look
If the request inside of Uniface succeeds, the screen will show the value of the Result. Otherwise an Error will be shown, where $status and the returned message is shown.
You'll will find more about JSON at http://www.json.org.
If you have improvements or suggests on this tool, just let me know and we will update this.
Update: one proc fitting all needs!M11 did some stuff on the code aswell as RichardGill. I wont hold that back from you so here comes M11's Extension.
Features-Recursive Code generation
-detects alpha and numeric values
Tell us, how you like that!
I am missing the escapes for special characters. Frank
sure... just handle it to me, so we can append this part
I have an improved version with recursion and using lists as follow: * indexed => array * associative => object Thus, with recursion, you can make arrays of objects, which contain arrays, etc.. Tell me if youre interested.