Ler Json Delphi 10.2
Olá pessoal,
Como faço para ler as infos do "Payment"?
As primeiras infos eu leio assim, normal:
Obrigado!
Como faço para ler as infos do "Payment"?
{
"code" : 0,
"message" : OK. Transaction successful.,
"payment" : {
"status" : NOV,
"nit" : 503d70ebaecd6730e594b8fcc45fa9304bf24cacce0c9c982ab00cb3cbeabdca,
"order_id" : 20170001,
"merchant_usn" : 20170001,
"amount" : 100000
}
}
"code" : 0,
"message" : OK. Transaction successful.,
"payment" : {
"status" : NOV,
"nit" : 503d70ebaecd6730e594b8fcc45fa9304bf24cacce0c9c982ab00cb3cbeabdca,
"order_id" : 20170001,
"merchant_usn" : 20170001,
"amount" : 100000
}
}
As primeiras infos eu leio assim, normal:
JsonObject := TJSONObject.ParseJSONValue( RESTResponse1.Content ) as TJSONObject; Memo1.Lines.Add( 'Code:' + JsonObject.GetValue('code').Value ); Memo1.Lines.Add( 'Message:' + JsonObject.GetValue('message').Value );
Obrigado!
Fernando Tremonti
Curtidas 1
Respostas
Natanael Ferreira
19/12/2017
Segue exemplo, extraindo todos os dados do Json:
var jsonObject, JsonObject2: TJsonObject; i: integer; begin Memo1.Clear; jsonObject := TJsonObject.ParseJSONValue(RESTResponse1.Content) as TJsonObject; JsonObject2 := jsonObject.Get('payment').JsonValue as TJsonObject; Memo1.Lines.Add('Code:' + jsonObject.GetValue('code').Value); Memo1.Lines.Add('Message:' + jsonObject.GetValue('message').Value); for i := 0 to JsonObject2.Size - 1 do Memo1.Lines.Add(JsonObject2.Get(i).JsonString.Value + ': ' + JsonObject2.Get(i).JsonValue.Value); end;
GOSTEI 0