I want to get all the users from this json.
{
"status": "ok",
"next_max_id": "AQAmA1l9NAQXa",
"sections": [
{
"module": null,
"show_view_all": null,
"title": null,
"users": [
{
"pk": 48165888,
"is_verified": false,
"profile_pic_url": "http://scontent-sit4-1.cdninstagram.com/t51.2885-19/s150x150/17332306_1915592632007479a.jpg",
"full_name": "Jason Giovany Castro Morales",
"is_private": false,
"has_anonymous_profile_picture": false,
"username": "jasongiovanycastromorales",
"profile_pic_id": "14699765111792881_48165888"
}
]
}
]
}
Now, my attempt to get all usernames.
procedure TForm2.Button6Click(Sender: TObject);
var
json : ISuperObject;
node : ISuperObject;
item : IMember;
begin
try
json := TSuperObject.Create(list.Text);
for item in json['sections.users'].AsArray do
begin
node := item.AsObject;
Memo4.Lines.Add(node.S['username']);
end;
finally
end;
end;
2nd attempt.. i get an AV !
var
json : ISuperObject;
node : ISuperObject;
item, item2 : IMember;
begin
json := SO(list.Text);
for item in json['sections'].AsArray do
begin
for item2 in json['users'].AsArray do
begin
node := item.AsObject;
Memo1.Lines.Add(node.S['username']);
end;
end;
end;
there are 200 username value in this JSON
I get nothing, sometimes AV when i try to play around withthe json code, my question is, how to parse this json correctly to get the value username? Thank You.
Your example is broken and you didn't specify the format of input data, like I don't know, if all objects in
sectionsarray containsusersarray. Anyway, this example should be working for your snippet.SuperObject
EDIT : In fact, you are not using
SuperObject, butX-SuperObject, which is something different. Even though I've never used that library, I was able to find the problem only with examples from their website, because u make simple mistakes like usingiteminstead ofitem2orjsonanditemin second loop.X-SuperObject