#include "protheus.ch"
Useruser Functionfunction tDelNameDNExemplo()
local oJson
local Localret
oJson := JsonObject():Newnew()
Local cJsonret := oJson:fromJson('{"titlecharacter": "example glossaryJoaquim", "name"json":{"Joao":22, "JohnJoana":33}'
Local cName := ""
Local cMsg := ""
Local lRet := .F.
oJson:fromJson( cJson , "array":[4,12,5], "numeric":23, "logic":false, "nil":null}')
// remove a propriedade de nome 'title' eif ValType(ret) == "U"
// exibe 'SUCCESS - JsonObject():DelName( "title" ) returned [.T.]'
cName := "title"
lRet := oJson:DelName( cName )
cMsg := ' - JsonObject():DelName( "' + cName + '" ) returned [' + cValToChar( lRet ) + ']'
If ( lRet )
ConOut( 'SUCCESS' + cMsg )
Else
ConOut( 'FAILURE' + cMsg )
EndIf
// não remove a propriedade de nome 'NAME' e
// exibe 'FAILURE - JsonObject():DelName( "NAME" ) returned [.F.]'
cName := "NAME"
lRet := oJson:DelName( cName )
cMsg := ' - JsonObject():DelName( "' + cName + '" ) returned [' + cValToChar( lRet ) + ']'
If ( lRet )
ConOut( 'SUCCESS' + cMsg )
Else
ConOut( 'FAILURE' + cMsg )
EndIf
FREEOBJ( oJson )
Return Conout("JsonObject populado com sucesso")
else
Conout("Falha ao popular JsonObject. Erro: " + ret)
endif
u_PrintJson(oJson)
/*
Será impresso:
Label - character
character = Joaquim
Label - numeric
numeric = 23
Label - logic
Label - array
Vetor[
Indice 1
4
Indice 2
12
Indice 3
5
]Vetor
Label - nil
Label - json
*/
oJson:DelName("json")
u_PrintJson(oJson)
/*
Label - character
character = Joaquim
Label - numeric
numeric = 23
Label - logic
Label - array
Vetor[
Indice 1
4
Indice 2
12
Indice 3
5
]Vetor
Label - nil
*/
return
|