Delphi / SuperObject - 访问返回NIL的子节点

时间:2016-05-10 20:19:57

标签: json delphi superobject

我从服务器获得以下JSON:

> str(data_test$Margin)
 Factor w/ 29 levels "1 wickets","10 wickets",..: 4 25 7 29 27 16 9 22 24 19 ...
> str(data_train$Margin)
 Factor w/ 29 levels "1 wickets","10 wickets",..: 10 25 17 11 24 28 19 3 10 3 ...

我使用以下代码访问此值:

{
  "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",
...

使用此代码,如果我使用简单的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; ,它会告诉我:

Label1.Caption := orderObj.AsString;

根据逻辑,"OrderId": "457634", "OrderNumber": "256176682", "OrderItems": { "OrderItem": { "OrderItemId": "712893", "ShopId": "14690930", "OrderId": "457634", ... 内部的值可以像这样访问OrderItem,但如果我尝试访问" easy"值orderObj['OrderItems.OrderItem'];,即第一个元素,使用OrderId返回orderObj['OrderId'];nil的所有节点都会发生相同的情况...

因此,无法访问orderObj中的值以转换为变量...

有一种方法可以访问orderObj.AsString内部的值吗?我的目标是使用以下代码将OrderItem的值转换为ClientDataSet:

OrderItem

谢谢!

1 个答案:

答案 0 :(得分:0)

这里你提到这个:

  

根据逻辑,OrderItem内部的值可以像这样访问:orderObj ['OrderItems.OrderItem'];

这确实有效。
但是在你写完这句话时,最后一句话就是矛盾的:

  

但是如果我尝试访问像OrderId这样的“简单”值,那就是第一个元素,使用orderObj ['OrderId'];

按照逻辑,正如您所说,访问您可以执行的值:

select id, count(distinct year)
from (select t.*,
             dense_rank() over (partition by id order by year + seqnum desc) as grp
      from (select t.*,
                   dense_rank() over (partition by id order by year desc) as seqnum
            from temp t
           ) t
     ) t
where grp = 1
group by id;

而不是直接orderObj['OrderItems.OrderItem.OrderId'];