Re: 2dim json arrays with scalar values

2017-07-27 Thread Rob Laveaux via 4D_Tech

> On 27 Jul 2017, at 15:43, Epperlein, Lutz (agendo) via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> OK, found it. It is possible. (To be honest, I didn't expect anything else)
> 
> The only question is now, how do I combine the code developed using 4D's 
> object commands with the NTK JSON API?

Hi Lutz,

Unfortunately the 4D Plugin SDK provides no direct support for C_OBJECT.

The solution is quite simple:
Use JSON Stringify to serialise the object to a JSON string. You can then pass 
this string to the NTK JSON commands.
When you need to do the reverse, you ask NTK to create a JSON string for you, 
which you can then pass to JSON Parse to get a C_OBJECT back.

So it is quite easy to mix it with existing code.

HTH,

- Rob Laveaux


Pluggers Software
Scholekstersingel 48
2496 MP  Den Haag
The Netherlands

Email: rob.lave...@pluggers.nl 
Website: http://www.pluggers.nl 





**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

RE: 2dim json arrays with scalar values

2017-07-27 Thread Epperlein, Lutz (agendo) via 4D_Tech
> The result should be:
> { "values": [
> [ 4711 ]
> ] }
> 
> Is this possible too?

OK, found it. It is possible. (To be honest, I didn't expect anything else)

The only question is now, how do I combine the code developed using 4D's object 
commands with the NTK JSON API?
E.g., I have a C_OBJECT variable $c_object. 
Is this possible:
JSON Set Object ($ntkObject;"chart";$c_object)

I assume the other way, setting a NTK object to a 4D C_OBJECT isn't possible, 
is it?

Remains the third way, rewriting all the code to the NTK API ...

Regards
Lutz

P.S: OK, there is a fourth way, don't use 4D for this, but this leads to 
complete rewrite.


**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

RE: 2dim json arrays with scalar values

2017-07-27 Thread Epperlein, Lutz (agendo) via 4D_Tech
Sounds good, how is it with the other way around?
Say, I have a 2dim longint array and would like to stringify it to json.

Pseudo code ( I don't know (yet) the API of the NTK plugin):


ARRAY LONGINT($values;1;1)
$values{1}{1}:=4711

JSON Set Array($object;”values”;$values)
$resultText:=JSON to Text($object)


The result should be:
{ "values": [
[ 4711 ]
] }

Is this possible too?

Thanks in advance
Lutz Epperlein


> -Original Message-
> From: 4D_Tech [mailto:4d_tech-boun...@lists.4d.com] On Behalf Of Rob Laveaux
> via 4D_Tech
> Sent: Thursday, July 27, 2017 2:35 PM
> To: 4D iNug Technical <4d_tech@lists.4d.com>
> Cc: Rob Laveaux 
> Subject: Re: 2dim json arrays with scalar values
> 
> 
> > On 27 Jul 2017, at 14:09, Epperlein, Lutz (agendo) via 4D_Tech
> <4d_tech@lists.4d.com> wrote:
> >
> > Is there any way to get the wanted result?
> 
> 
> Hi Lutz,
> 
> Yes, there is. Use the JSON commands from NTK Plugin.
> 
> Here is some example code:
> 
> $object:=JSON Parse Text($json)
> If ($object#0)
>   $array1:=JSON Get Array($object;”values”)
>   $count1:=JSON Count Items($array1)
>   For($i;1;$count1)
>   $array2:=JSON Get Array($array1;String($i))
>   $count2:=JSON Count Items($array2)
>   For($j;1;$count2)
>   $value:=JSON Get Number($array2;String($j))
>   End for
>   End for
>   JSON Release($object)
> End if
> 
> HTH,
> 
> - Rob Laveaux
> 
> 
> Pluggers Software
> Scholekstersingel 48
> 2496 MP  Den Haag
> The Netherlands
> 
> Email: rob.lave...@pluggers.nl <mailto:rob.lave...@pluggers.nl>
> Website: http://www.pluggers.nl <http://www.pluggers.nl/>
> 
> 
> 
> 
> 
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: 2dim json arrays with scalar values

2017-07-27 Thread Rob Laveaux via 4D_Tech

> On 27 Jul 2017, at 14:09, Epperlein, Lutz (agendo) via 4D_Tech 
> <4d_tech@lists.4d.com> wrote:
> 
> Is there any way to get the wanted result? 


Hi Lutz,

Yes, there is. Use the JSON commands from NTK Plugin.

Here is some example code:

$object:=JSON Parse Text($json)
If ($object#0)
$array1:=JSON Get Array($object;”values”)
$count1:=JSON Count Items($array1)
For($i;1;$count1)
$array2:=JSON Get Array($array1;String($i))
$count2:=JSON Count Items($array2)
For($j;1;$count2)
$value:=JSON Get Number($array2;String($j))
End for
End for
JSON Release($object)
End if

HTH,

- Rob Laveaux


Pluggers Software
Scholekstersingel 48
2496 MP  Den Haag
The Netherlands

Email: rob.lave...@pluggers.nl 
Website: http://www.pluggers.nl 





**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**