<br><div>unit Unit1;</div><div><br /></div><div>interface</div><div><br /></div><div>uses</div><div> Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,</div><div> Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,DBXJSON;</div><div><br /></div><div>type</div><div> TForm1 = class(TForm)</div><div> Button1: TButton;</div><div> procedure Button1Click(Sender: TObject);</div><div> private</div><div> { Private declarations }</div><div> public</div><div> { Public declarations }</div><div> end;</div><div><br /></div><div>var</div><div> Form1: TForm1;</div><div><br /></div><div>implementation</div><div><br /></div><div>{$R *.dfm}</div><div><br /></div><div>const</div><div> GJSONString =</div><div> '{' +</div><div> ' "name": {'+</div><div> ' "A JSON Object": {' +</div><div> ' "id": "1"' +</div><div> ' },' +</div><div> ' "Another JSON Object": {' +</div><div> ' "id": "2"' +</div><div> ' }' +</div><div> ' },' +</div><div> ' "totalobjects": "2"' +</div><div> '}';</div><div><br /></div><div>procedure TForm1.Button1Click(Sender: TObject);</div><div>var</div><div> LJSONObject: TJSONObject;</div><div> Value: TJSONValue;</div><div>begin</div><div> LJSONObject := nil;</div><div> try</div><div> LJSONObject := TJsonObject.Create;</div><div> Value := TJSONValue.Create;</div><div> { convert String to JSON }</div><div> LJSONObject.Parse(BytesOf(GJSONString), 0);</div><div> Value :=LJSONObject.GetValue('name');</div><div> ShowMessage(Value.ToString);</div><div> finally</div><div> LJSONObject.Free;</div><div> end;</div><div>end;</div><div><br /></div><div>end.</div><div><span style="font-family:Consolas, 'Courier New', Courier, mono, serif;">http://docwiki.embarcadero.com/RADStudio/XE5/en/JSON</span></div> <br>
t Unit2;