Obter Name de um Json.

Android

Delphi

FireMonkey

08/01/2019

OI...
Sou meio novo aqui em Delphi tbm...
Gostaria de saber se a algum modo de obter o name do json, tipo guardar ele em uma string, so o name mesmo....
No delphi FMX...
Abrss...
Fernando

Fernando

Curtidas 0

Respostas

Fernando Ito

Fernando Ito

08/01/2019

Falae Fernando,

segue um exemplo de como você pode fazer isso:

var
jsonObj, jSubObj: TJSONObject;
jv: TJSONValue;
begin
jsonObj := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(Memo1.Text), 0)
as TJSONObject;

Memo1.Lines.Clear;

jv := jsonobj.Get('error').JsonValue;
jsubObj := jv as TJSONObject;

jv := jsubObj.Get('message').JsonValue;
jsubObj := jv as TJSONObject;

jv := jsubObj.Get('value').JsonValue;

ShowMessage(jv.Value);
end;

Um abraço,
ITO
GOSTEI 0
Fernando

Fernando

08/01/2019

Falae Fernando,

segue um exemplo de como você pode fazer isso:

var
jsonObj, jSubObj: TJSONObject;
jv: TJSONValue;
begin
jsonObj := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(Memo1.Text), 0)
as TJSONObject;

Memo1.Lines.Clear;

jv := jsonobj.Get('error').JsonValue;
jsubObj := jv as TJSONObject;

jv := jsubObj.Get('message').JsonValue;
jsubObj := jv as TJSONObject;

jv := jsubObj.Get('value').JsonValue;

ShowMessage(jv.Value);
end;

Um abraço,
ITO


Obrigado pela resposta, vou testa.
Estou em outros projetos...

Mas muito obrigado mesmo.
GOSTEI 0
POSTAR