I have the following JSON from server:
{
"SuccessResponse": {
"Head": {
"RequestId": "",
"RequestAction": "GetMultipleOrderItems",
"ResponseType": "Orders",
"Timestamp": "2016-05-10T15:13:06-0300"
},
"Body": {
"Orders": {
"Order": [
{
"OrderId": "457634",
"OrderNumber": "256176682",
"OrderItems": {
"OrderItem": {
"OrderItemId": "712893",
"ShopId": "14690930",
"OrderId": "457634",
...
I'm using the following code to access this values:
procedure TForm1.GetOrdersPendingItems;
var
mydata : string;
obj, orderObj: ISuperObject;
orderArray: TSuperArray;
begin
mydata := GetURLAsString(GenerateApiUrl('GetMultipleOrderItems', 'OrderIdList', '[457634,457817]'));
obj := SO(mydata);
orderObj := obj['SuccessResponse.Body.Orders.Order'];
end;
With this code, if I use a simple Label1.Caption := orderObj.AsString;, it show me this:
"OrderId": "457634",
"OrderNumber": "256176682",
"OrderItems": {
"OrderItem": {
"OrderItemId": "712893",
"ShopId": "14690930",
"OrderId": "457634",
...
By the logic, the values inner of OrderItem can be access like this: orderObj['OrderItems.OrderItem'];, but if I try to access a "easy" value like OrderId, that is the first element, using orderObj['OrderId']; it returns nil and the same happens with all nodes of the orderObj...
So, the values in the orderObj.AsString can't be accessed to convert into variable...
There are a way to access the value inner of OrderItem? My objective is convert the values of OrderItem into a ClientDataSet using the following code:
orderArray := orderObj.AsArray;
TJSONDB.JsonToClientDataSet(orderArray, cdsOrdersItems);
Thanks!
Here you mention this:
This would work, indeed.
But right after you wrote this contradicting the last sentence:
By the logic, as you say, to access the values you could do:
and not
orderObj['OrderId'];directly.