Fórum Ler JSON específico #615722
10/05/2021
0
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
Curtir tópico
+ 0Post mais votado
10/05/2021
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;Natanael Ferreira
Gostei + 1
Mais Posts
10/05/2021
Gxf
Gostei + 0
10/05/2021
Cezar Lopes
Esse código que passaste eu já vi. Ele não dá erro, mas também mão faz nada! :(
Gostei + 0
10/05/2021
Cezar Lopes
:)
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
Clique aqui para fazer login e interagir na Comunidade :)