Hello Aparajita

Until now I have done all JSON encodings myself (Active4D <-> Ajax Requests)  
and start now using the new Native Active 4D JSON commands.
THIS IS AWESOME!!!! Many thanks to Aparajita.

Example:

<%
//Active 4D Response to a Ajax Request
$c:=new collection
ARRAY Date($c{"aDate"};*;!1.1.1900!;current date)
$c{"adresses"}:=new collection
$c{"adresses"}{"10423"}:=new 
collection("fistname";"Freddie";"lastname";"Freeloader")
$c{"adresses"}{"10442"}:=new 
collection("fistname";"Bianca";"lastname";"Castafiore")
$c{"adresses"}{"date1"}:=current date

$json := json encode($c)
writeln($json)  //  {"adresses":{"date1":"Oct 7, 
2013","10442":{"lastname":"Castafiore","fistname":"Bianca"},"10423":{"lastname":"Freeloader","fistname":"Freddie"}},"aDate":["Jan
 1, 1900","Oct 7, 2013"]} 

%>

<%
// Ajax Request send JSON

$cData := parse json($json;"/date1|aDate/")     // return a Active 4D 
Collection with the correct data structure!!!  date1 and the array aDate with 
date format

/*
$c
        aDate: [0] {01.01.00, 07.10.13}
        adresses: 
                10423: 
                        fistname: "Freddie"
                        lastname: "Freeloader"
                10442:
                        fistname: "Bianca"
                        lastname: "Castafiore"
                date1: Oct 7, 2013
*/

%>


Use Active 4D json encode and parse json, and work on the other side in 
Javascript with jQuery to encode/decode JSON into/from Javascript Objects.


A small mistake in the manual v6.1r1 page 235
$data := parse json($json; true; "/^birthdate$/")       // error
$data := parse json($json; "/^birthdate$/";true)        // ok


Regards, Oliver
_______________________________________________
Active4D-dev mailing list
[email protected]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/

Reply via email to