#include "protheus.ch"
user function GJTExemplo()
local oJson
local ret
oJson := JsonObject():new()
ret := oJson:fromJson('{"character":"Joaquim", "json":{"Joao":22, "Joana":33}, "array":[4,12,5], "numeric":23, "logic":false, "nil":null, "CArr":["Joaquim","Ana","joao"]}')
if ValType(ret) == "U"
Conout("JsonObject populado com sucesso")
else
Conout("Falha ao popular JsonObject. Erro: " + ret)
endif
ret := oJson:GetJsonText("character")
conout (ret)
/*
Será impresso:
Joaquim
*/
ret := oJson:GetJsonText("json")
conout (ret)
/*
Será impresso:
{"Joana":33,"Joao":22}
*/
ret := oJson:GetJsonText("array")
conout (ret)
/*
Será impresso: (string vazia)
[4,12,5]
*/
ret := oJson:GetJsonText("numeric")
conout (ret)
/*
Será impresso: (string vazia)
23
*/
ret := oJson:GetJsonText("logic")
conout (ret)
/*
Será impresso: (string vazia)
false
*/
ret := oJson:GetJsonText("nil")
conout (ret)
/*
Será impresso:
null
*/
(string vazia)
ret := oJson:GetJsonText("CArr")
conout (ret)
/*
Será impresso:
["Joaquim","Ana","joao"]
*/
FreeObj(oJson)
return |