I need to make the behavior of certain parts of my simulation dependent on the data returned by a call to a RESTful service. The JSON that comes back is relatively complicated:
{result:[<resultset>|<record>,<resultset>|<record>,<resultset>|<record>,<resultset>|<record>,<resultset>|<record>,<resultset>|<record>]}
a resultset is an object that looks like:
{ referenceName: "some-string", limit: 20, offset: 0, total: <n>, recommendations: [<record>,...] }
a record contains information about what was searched for, and depending on which position in the result list, it will have different fields. In one case, it looks like:
`
{
id: #####,
firstName: “first”,
lastName: “last”,
name: “last, first, title”,
location: ,
refs: [,…]
}
`
In the rest, it is missing a few fields, but it is still not a simple object
What I need is to add logic to my scenario that lets it understand what was returned. If a record was returned, some options are available to me. If a resultset, then I have different options. When a resultset, I need to parse the list of results, and be able to pick one, and then transform that data into the format needed for posting back to the server.
In an ideal world, I would be able to parse the whole JSON object, and store it in session as an object, not a string. Then I could navigate it easily enough. But I have not seen anything in the documentation indicating that it is possible to do that. I have seen examples for parsing a single flat object, but not an object with an embedded array of objects in one field that happens to have some number of objects in which you will find other embedded arrays and objects!
What is the shortest path between where I am and what I want to accomplish?