Histórico da Página
| Composition Setup |
|---|
import.css=/download/attachments/6062824/tecnologia.css
|
...
Retorna um objeto do tipo JsonObject que seja o conteúdo
...
da propriedade informada.
Sintaxe
| Bloco de código |
|---|
JsonObject:GetJsonObject( cPropriedade )
|
Parâmetros
| Nome | Tipo | Descrição | Obrigatório | Referência |
|---|---|---|---|---|
| cPropriedade | caractere | Nome da propriedade cujo valor será retornado | X |
Retorno
Nome | Tipo | Descrição |
|---|---|---|
oJsonObj | JsonObject |
...
Objeto contido na propriedade informada. |
Exemplo
| Bloco de código | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
user function exemploGJO()
local oJson
local ret
oJson := JsonObject():new()
ret := oJson:fromJson('{"name":{"John":1, "Mary":2}, "age":31, "city":"New York"}')
if ValType(ret) == "U"
Conout("JsonObject populado com sucesso")
else
Conout("Falha ao popular JsonObject. Erro: " + ret)
return
endif
ret := oJson:GetJsonObject("name")
if ValType(ret) == "J"
u_PrintJson(ret)
else
if ValType(ret) <> "U"
conout(cValtochar(ret))
else
conout("falha ao obter JsonObject")
endif
endif
/*
Será impresso:
Label - John
John = 1
Label - Mary
Mary = 2
*/
ret := oJson:GetJsonObject("age")
if ValType(ret) == "J"
u_PrintJson(ret)
else
if ValType(ret) <> "U"
conout(cValtochar(ret))
else
conout("falha ao obter JsonObject")
endif
endif
/*
Será impresso:
31
*/
ret := oJson:GetJsonObject("esto non exist")
if ValType(ret) == "J"
u_PrintJson(ret)
else
if ValType(ret) <> "U"
conout(cValtochar(ret))
else
conout("falha ao obter JsonObject")
endif
endif
/*
Será impresso:
falha ao obter JsonObject
*/
FreeObj(oJson)
return
user function PrintJson(jsonObj)
local i, j
local names
local lenJson
local item
if ValType(jsonObj) <> "J"
conout("PrintJson --> objeto recebido nao é um JsonObject")
return
endif
lenJson := len(jsonObj) if lenJson > 0 for i := 1 to lenJson u_PrintJson(jsonObj[i]) next else names := jsonObj:GetNames() for i := 1 to len(names) conout("Label - " + names[i]) item := jsonObj[names[i]] if ValType(item) == "C" .or. ValType(item) == "N" conout( names[i] + " = " + cvaltochar(jsonObj[names[i]])) else if ValType(item) == "A" conout("Vetor[") for j := 1 to len(item) conout("Indice " + cValtochar(j)) if ValType(item[j]) == "J" u_PrintJson(item[j]) else conout(cvaltochar(item[j])) endif next j conout("]Vetor") endif endif next i endif return |
Observações:
Disponível em build igual ou superior a 17.2.1.0
| Composition Setup |
|---|
import.css=/download/attachments/6062824/tecnologia.css
|
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas