0

I have my JSON as

{{
  "attributes": {
    "type": "User",
    "url": "/services/data/v44.0/sobjects/User/0052F000002bO32QAE"
  },
  "Name": "demo Site Guest User",
  "UserType": "Guest",
  "Profile": {
    "attributes": {
      "type": "Profile",
      "url": "/services/data/v44.0/sobjects/Profile/00e2F000000DuoFQAS"
    },
    "Id": "00e2F000000DuoFQAS",
    "Name": "demo Profile"
  }
}}

{{
  "attributes": {
    "type": "User",
    "url": "/services/data/v44.0/sobjects/User/00541000006I1JyAAK"
  },
  "Name": "Scheduler Site Guest User",
  "UserType": "Guest",
  "Profile": {
    "attributes": {
      "type": "Profile",
      "url": "/services/data/v44.0/sobjects/Profile/00e41000000GhKdAAK"
    },
    "Id": "00e41000000GhKdAAK",
    "Name": "Scheduler Profile"
  }
}}

In the above JSON, I want to fetch parent elements 'Name' and 'UserType' and child elements'Id' and 'Name' and convert into datatable. These parent and child elements are anonymous so I can't create classes for those.

I got up to here

dynamic responseRecs = (responseDetails.records as IEnumerable<object>).Cast<object>().ToList();

which is giving me the response but not sure how to loop through the dynamic and get parent and child line items (ignoring the type and url) so that I can build a datatable.

Any help will be greatly appreciated. Thanks

er-sho
  • 9,581
  • 2
  • 13
  • 26
rks
  • 1
  • your json always wrap with double curly brackets? – er-sho Dec 14 '18 at 05:33
  • have a look at this approach [Convert Json to DataTable](https://stackoverflow.com/a/27282579/2417602) – vikscool Dec 14 '18 at 05:33
  • the both json snippet you shown in above is in same json or both are different json? – er-sho Dec 14 '18 at 05:50
  • Yes, my json always wrap with double curly brackets. It is the salesforce response that I am getting when querying user and profile tables with query REST API. I shown two rows of the return data that I am getting. – rks Dec 14 '18 at 14:37
  • I looked into the Convert JSON to DataTable approach suggested by vikscool but failing to do so because of type and url fields in parent and child. I want to ignore those fields in my datatable. Tried with JSON settings but no luck. – rks Dec 14 '18 at 14:41

0 Answers0