Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/JSON/Delphi/json.delphi
Normal file
55
Task/JSON/Delphi/json.delphi
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
program JsonTest;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
{$R *.res}
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
Json;
|
||||
|
||||
type
|
||||
TJsonObjectHelper = class helper for TJsonObject
|
||||
public
|
||||
class function Deserialize(data: string): TJsonObject; static;
|
||||
function Serialize: string;
|
||||
end;
|
||||
|
||||
{ TJsonObjectHelper }
|
||||
|
||||
class function TJsonObjectHelper.Deserialize(data: string): TJsonObject;
|
||||
begin
|
||||
Result := TJSONObject.ParseJSONValue(data) as TJsonObject;
|
||||
end;
|
||||
|
||||
function TJsonObjectHelper.Serialize: string;
|
||||
begin
|
||||
Result := ToJson;
|
||||
end;
|
||||
|
||||
var
|
||||
people, deserialized: TJsonObject;
|
||||
bar: TJsonArray;
|
||||
_json: string;
|
||||
|
||||
begin
|
||||
people := TJsonObject.Create();
|
||||
people.AddPair(TJsonPair.Create('1', 'John'));
|
||||
people.AddPair(TJsonPair.Create('2', 'Susan'));
|
||||
|
||||
_json := people.Serialize;
|
||||
Writeln(_json);
|
||||
|
||||
deserialized := TJSONObject.Deserialize(_json);
|
||||
Writeln(deserialized.Values['2'].Value);
|
||||
|
||||
deserialized := TJSONObject.Deserialize('{"foo":1 , "bar":[10,"apples"]}');
|
||||
|
||||
bar := deserialized.Values['bar'] as TJSONArray;
|
||||
Writeln(bar.Items[1].Value);
|
||||
|
||||
deserialized.Free;
|
||||
people.Free;
|
||||
|
||||
Readln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue