I want to check if the JSON object has the key "error"
. If it has, I want to "continue" the loop, otherwise the program can go to all the loop.
This is the JSON:
[
{
"cenario": {
"origem": "",
"out": "SNC",
"country": "",
},
"item": "0015963",
"cod": "17894904009319",
"nat_rec": null
},
{
"item": "0012868",
"error": "product unavailable",
"status": "unavailable",
}
]
How can I check if the object that I'm reading has the key "error"
or not?
I tried:
jValue.FindValue('error') // The problem it's going to search for all objects.
jValue.TryGetValue('error', jArray) // if it doesn't find the key in the index that it's searching at the moment, it breaks the application.
I'm doing:
response:= IdHTTP.Get(url);
jValue:= TJsonObject.ParseJSONValue(response);
for x := 0 to 2 do
begin
if jValue.TryGetValue('error', jvalue) then
begin
continue;
end;
memo.Lines.Add('cod_item :' + jValue.GetValue<string>('['+intToStr(x)+'].item'));
memo.Lines.Add('cod: ' + jValue.GetValue<string>('['+intToStr(x)+'].cod'));
end;