Closed chonghai closed 8 years ago
just like this question: http://stackoverflow.com/questions/33127718/how-can-i-access-a-sub-object-in-jsondataobjects
You can iterate through the array or you can use the Path[] property.
procedure Test(AData: TJsonObject);
var
Obj: TJsonObject;
begin
Obj := AData.Path['MyArray[1].MySubObject'];
...
end;
thks for your answer. but I test it , it seems not work. here is some JSON string:
{"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "Help"}, {"id": "About", "label": "About Adobe CVG Viewer..."} ] }}
How can I Get "Help" in {"id": "Help"}? Thks!
if Json.Path['menu.items[3].id'] <> 'Help' then
raise Exception.Create('Something is wrong');
sorry, I make mistake, I user a wrong JSON string. Your code is good.
another question: How to use iterate through the array to show each "id"? like:
for jsonitem in obj['menu'].['items'] do
showMessage(jsonitem['id']);
"for in" is not supported. You have to iterate manually using the array's Count property.
OK, thanks a lot of!
How to get each item(Object, not a single Value) from the ARRAY? thks!