Ler JSON específico
Olá pessoal!
Estou com dificuldade para ler este json e jogá-lo num objeto ou num clientdataset.
{"success":["705","330","547"],"errors":[]}.
Todos os exemplos que utilizei redundaram em invalid type cast.
Alguém pode me auxiliar?
Obrigado!
Estou com dificuldade para ler este json e jogá-lo num objeto ou num clientdataset.
{"success":["705","330","547"],"errors":[]}.
Todos os exemplos que utilizei redundaram em invalid type cast.
Alguém pode me auxiliar?
Obrigado!
Cezar Lopes
Curtidas 0
Melhor post
Natanael Ferreira
10/05/2021
Veja um exemplo simples:
Acrescente DBXJson na uses do form.
Acrescente DBXJson na uses do form.
var
jObj: TJSONObject;
jArray: TJSONArray;
jValue: TJSONValue;
i: Integer;
begin
jObj := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(Memo1.Text), 0) as TJSONObject;
if jObj = nil then
Application.MessageBox('Arquivo json inválido.', 'Erro', MB_OK + MB_ICONERROR)
else
begin
jValue := jObj.Get('success').JsonValue;
if jValue.ClassType = TJSONArray then
begin
jArray := (jValue as TJSONArray);
for I := 0 to jArray.Size - 1 do
ShowMessage(jArray.Get(i).Value);
end;
end;
end;GOSTEI 1
Mais Respostas
Gxf
10/05/2021
https://pt.stackoverflow.com/questions/391976/como-ler-um-arquivo-json-pelo-delphi
GOSTEI 0
Cezar Lopes
10/05/2021
Bom dia!
Esse código que passaste eu já vi. Ele não dá erro, mas também mão faz nada! :(
Esse código que passaste eu já vi. Ele não dá erro, mas também mão faz nada! :(
https://pt.stackoverflow.com/questions/391976/como-ler-um-arquivo-json-pelo-delphi
GOSTEI 0
Cezar Lopes
10/05/2021
Bom dia Natanael. Muitíssimo obrigado. Deu certo! Valeu mesmo!
:)
:)
Veja um exemplo simples:
Acrescente DBXJson na uses do form.
Acrescente DBXJson na uses do form.
var
jObj: TJSONObject;
jArray: TJSONArray;
jValue: TJSONValue;
i: Integer;
begin
jObj := TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(Memo1.Text), 0) as TJSONObject;
if jObj = nil then
Application.MessageBox('Arquivo json inválido.', 'Erro', MB_OK + MB_ICONERROR)
else
begin
jValue := jObj.Get('success').JsonValue;
if jValue.ClassType = TJSONArray then
begin
jArray := (jValue as TJSONArray);
for I := 0 to jArray.Size - 1 do
ShowMessage(jArray.Get(i).Value);
end;
end;
end;GOSTEI 0