0

I have a REST call that is working properly. I can pass parameters, it returns data.

The app uses TRESTClient, TRESTResponse, TRESTRequest, TRESTAdapter, feeding into TClientDataSet and TDataSource.

The end result is that when the JSON data comes in, I can iterate through it as if it was a table. With simple JSON, I can get this working.

I am now querying a REST service which is providing data that is one level deeper than normal. See JSON below.

Everything I need to access is UNDER the mycursor element, which is under the items element.

I can't change the REST service, so how can I tell one of these components to ignore the items level and look at the mycursor level?

The data I am looking to parse has a first element of id.

{
  "next":
  {
    "$ref":"https://<internal URL>/?page=1"
  },
  "items":
  [
    {
      "mycursor":
      [
        {
          "id":13372,
             …
        },
        {
          "id":13373,
           …
        },            
        {
          "id":13374,
              …
        },            
        {
          "id":13375,
           …
        },            
        {
          "id":13376,
            …
        }
      ]
    }
  ]
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user1009073
  • 3,160
  • 7
  • 40
  • 82
  • How are you loading the JSON into the `TClientDataSet`? Please show your actual code. Obviously, you are going to have to do some lre-processing of the JSON before you load it. – Remy Lebeau Feb 23 '18 at 14:42
  • @Remy, I am not "loading" it into TClientDataSet. As all 6 objects are tied together, when I RestRequest.Execute (after putting in Resource, etc), the data is then in TDatasource. The loading/parsing is happening within the VCL control itself. – user1009073 Feb 23 '18 at 18:41
  • Like I said, you likely won't be able to do that anymore if you have to massage the data. You will have to download the JSON first, parse/modify it as needed, and then load the result into the `TDataSource`. Unless the RESTAdapter has the ability to do that massaging for you, but you didn't say *which* RESTAdapter you are using, or how you are using it. – Remy Lebeau Feb 23 '18 at 18:59
  • @Remy, ahh... I didnt, did I. Sorry about that. It is the Delphi TRestResponseDataSetAdapter. – user1009073 Feb 23 '18 at 21:42
  • 1
    `TRESTResponse` and `TRESTResponseDataSetAdapter` both have a `RootElement` property. Use that property to tell the REST framework where to start returning record values from within the overall JSON. In your case, something like `'items[0].mycursor'`. – Remy Lebeau Feb 23 '18 at 22:00
  • @Remy - I knew about the property, I just couldn't get the syntax set properly... Thank you. Submit as answer, and I will accept. – user1009073 Feb 24 '18 at 11:03

0 Answers0