You are not logged in.
Pages: 1
Hello
I need help.
I have the next json
[
{
"id": "f7518487-6e95-4c90-8438-a6b48d6a8b5f",
"name": "user",
"phones": [
{
"type": "mobile"
"number": "123-456-789"
}
]
}
]
I need to get the value of nested array phones[0].number
How can i do this via IDocList?
PS. Sorry for my English
Offline
var
d1, d2: IDocDict;
l: IDocList;
begin
l := DocList(j);
for d1 in l do
for d2 in d1.L['phones'] do
writeln(d2['number']);
end;
Offline
This code works on Delphi but not on FPC, due to a FPC bug.
On FPC:
var
d1, d2: IDocDict;
l1, l2: IDocList;
begin
l1 := DocList(j);
for d1 in l1 do
begin
l2 := d1.L['phones'];
for d2 in l2 do
writeln(d2['number']);
end;
end;
Offline
I use delphi XE, mORMot 2.3 stable
and get compiler error "[DCC Error] TestApp_FMain.pas(1645): E2010 Incompatible types: 'Integer' and 'string'
for d1 in DocList(json) do
for d2 in d1.L['phones'] do // Exception is here
writeln(d2['number']);
Offline
/// access one element in the list, as IDocList (List)
// - warning: weak reference to the main list, unless you explicitly Copy it
property L[position: integer]: IDocList
read GetL write SetL;
what means "position" in this context?
Offline
thanks for everyone
all works after change IDocList to IDocDict
Offline
Pages: 1