Can someone please help me with the correct syntax to access a string inside a nested object using JSONDataObjects from Andreas Hausladen
I have a JSON string returned from an API that contains an array of customers followed by a cursor pagination object (meta) eg
{
"customers": [
{
"id": "CU000DWEQWMRN4",
"email": "[email protected]",
"metadata": {
"member_name": "BLOGGS jim",
"membership_id": "4088"
}
},
{
"id": "CU000DVEKR579S",
"email": "[email protected]",
"metadata": {
"membership_id": "5647"
}
}
],
"meta": {
"cursors": {
"before": null,
"after": "ID456"
},
"limit": 50
}
}
I an trying to get the values of before and after inside the meta object at the end
What I have tried
var Obj: TJsonObject;
AfterID : string;
begin
Obj := TJsonObject.Parse(theJSON) as TJsonObject;
AfterID := Obj['meta']['cursors']['after'] ;
Problem I get the error message cannot convert object to string
I also tried
var
Obj: TJsonObject;
AfterID : string;
begin
obj := Obj['meta'];
Obj := Obj['cursors'];
AfterID := Obj['after'];
Problem I get the error message cannot convert object to string
I've also tried many other combinations of syntax but I won't clutter the question with all of those!
I am puzzled as I my syntax is correct when doing the same thing with a slightly different JSON retuned from another API that has a simpler cursor pagination structure eg
{
"items": [
{
"event": "accepted",
"id": "G3wOhh",
"user-variables": {},
"log-level": "info",
"method": "smtp"
},
{
"event": "accepted",
"id": "KLT56",
"user-variables": {},
"log-level": "info",
"method": "smtp"
}
],
"paging": {
"previous": "line 4",
"first": "line 1",
"last": "line 12",
"next": "line 6"
}
}
with this JSON, using
var
Obj : TJsonObject;
nextID : string;
begin
Obj := TJsonObject.Parse(TheReturnedJSON) as TJDOJsonObject;
nextID := Obj['paging']['next'];
I get the correct value returned