Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this sample</p> <pre><code>{$APPTYPE CONSOLE} {$R *.res} uses DBXJSON, System.SysUtils; Const StrJson= '{'+ ' "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'+ '}'; procedure ParseJson; var LJsonObj : TJSONObject; LJPair : TJSONPair; LProducts : TJSONValue; LProduct : TJSONValue; LItem : TJSONValue; LIndex : Integer; LSize : Integer; begin LJsonObj := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(StrJson),0) as TJSONObject; try LProducts:=LJsonObj.Get('products').JsonValue; LSize:=TJSONArray(LProducts).Size; for LIndex:=0 to LSize-1 do begin LProduct := TJSONArray(LProducts).Get(LIndex); LJPair := TJSONPair(LProduct); Writeln(Format('Product Name %s',[LJPair.JsonString.Value])); for LItem in TJSONArray(LJPair.JsonValue) do begin if TJSONPair(LItem).JsonValue is TJSONFalse then Writeln(Format(' %s : %s',[TJSONPair(LItem).JsonString.Value, 'false'])) else if TJSONPair(LItem).JsonValue is TJSONTrue then Writeln(Format(' %s : %s',[TJSONPair(LItem).JsonString.Value, 'true'])) else Writeln(Format(' %s : %s',[TJSONPair(LItem).JsonString.Value, TJSONPair(LItem).JsonValue.Value])); end; end; finally LJsonObj.Free; end; end; begin try ParseJson; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. </code></pre> <p>This will return</p> <pre><code>Product Name Men's Sneakers instock : false size : 423 manufacturer : Adidas lastcheck : 20120529 Product Name Purse instock : true size : not applicable manufacturer : Prada lastcheck : 20120528 Product Name Men's Hood instock : false size : M manufacturer : Generic lastcheck : 20120529 </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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