Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse nested JSON object in Delphi XE2?
    primarykey
    data
    text
    <p>I'm new to JSON and I have this project on my hands that require me to parse a JSON and display some of its contents in a ListView. The problem is that the documentation I've read by now dealt with JSON objects containing JSON arrays, while my case involves dealing with nested objects. To cut the story short, here's the summary: I'm using Delphi XE2 with DBXJSON. I post some values to a server and it replies with a JSON object that looks like that:</p> <pre><code> { "products": { "Men's Sneakers": { "instock": false, "size": "423", "manufacturer": "Adidas", "lastcheck": "20120529" }, "Purse": { "instock": true, "size": "not applicable", "manufacturer": "Prada", "lastcheck": "20120528" }, "Men's Hood": { "instock": false, "size": "M", "manufacturer": "Generic", "lastcheck": "20120529" } }, "total": 41, "available": 30 } </code></pre> <p>What I wanted to achieve was to have each item (i.e. Purse) parsed and added as caption in a listview, along with one subitem (manufacturer). I created a procedure that takes the JSON string as argument, created the JSON object, but I don't know how to parse the nested objects any further.</p> <pre><code>procedure TForm1.ParseString(const AString: string); var json : TJSONObject; jPair : TJSONPair; jValue : TJSONValue; jcValue : TJSONValue; l,i : Integer; begin json := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(AString),0) as TJSONObject; try //get the pair to evaluate in this case the index is 1 jPair := json.Get(1); {further process the nested objects and adding them to the listview} finally json.Free; end; end; </code></pre> <p>Any suggestions would be highly appreciated. Lost quite some time trying to get the ins and outs of JSON in Delphi with no avail.</p> <p>Thanks, sphynx</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload