Ver Mensaje Individual
  #3  
Antiguo 05-08-2020
(MAJ) (MAJ) is offline
Miembro
 
Registrado: abr 2007
Posts: 71
Reputación: 18
(MAJ) Va por buen camino
Buenas compañero

Cita:

Lo que necesito es leer el JSON y sacar las claves, dependieno al nombre ya puedo entrar a tomar el valor que necesito, ya que no puedo obtener la clave Estado cuando la clave puede ser Mensaje y ahí obtengo error.

se me ocurre algo así



Código Delphi [-]
  procedure ParseJSON;
var

JObject: TJsonObject;
JEstado: TJValue;
JCode: TJValue;
JMessage: TJValue

begin
  JObject:= TJSONObject.ParseJSONValue(Memo1.text) as TJSONObject;
  

  JEstado:= JObject.FindValue('estado');
  JMessage:= JObject.FindValue('message');



  if Assigned(JEstado) then
  begin

    Memo2.Text:= JEstado.Value' - '+JMessage.Value
  end;

 else
   begin
     JCode:= JObject.FindValue('code');
     if Assigned(JCode) then
     begin
       Memo2.Text:= JCode.Value' - '+JMessage.Value;
     end;

   end;
end;


espero que te sirva, no se si es lo mejor pero creo que puede servirte
__________________
Código Delphi [-]
//Inserte una firma aquí...
Responder Con Cita