CLOSE ALL
CLEAR ALL
CLEAR

SET PROCEDURE TO qdfoxJSON
JSONStart()

?"JSON Test #1"
?"Version " + JSON.Version
?
?"THIS TEST SHOWS HOW TO USE ENCODE AND DECODE OBJECTS USING JSON HELPER"
?
?"Creating test object..." 

LOCAL o
#IF VERSION(5) >= 800
 o = CREATEOBJECT("Empty")    && Empty object
#ELSE
 o = CREATEOBJECT("JSONEmpty")
#ENDIF
AddProperty(o, "firstName","Victor")
AddProperty(o, "lastName","Espina")
AddProperty(o, "Country","Venezuela")

LOCAL ARRAY aLangs[3]
aLangs[1] = "VFP"
aLangs[2] = "C#"
aLangs[3] = "PHP"
AddProperty(o, "Languages[1,1]","")
ACOPY(aLangs,o.Languages) 

??"Done!"

?"Serializing object..."
LOCAL cJSON
cJSON = JSON.Encode(o)
?cJSON

?
?"Deserializing object..."
RELEASE o
o = JSON.Parse(cJSON)
?"Name"
?"",o.firstName, o.lastName

?"Languages"
#IF VERSION(5) >= 700
 ?"",o.Languages[1]
 ?"",o.Languages[2]
 ?"",o.Languages[3]
#ELSE
 ?"",o.Languages.Item[1]
 ?"",o.Languages.Item[2]
 ?"",o.Languages.Item[3]
#ENDIF
 
?
?"Test completed"
?
?"For more information, read initial comments at qdfoxJSON.PRG file"

