在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ahausladen/JsonDataObjects开源软件地址:https://github.com/ahausladen/JsonDataObjects开源编程语言:Pascal 100.0%开源软件介绍:Json Data ObjectsThis Delphi unit contains a JSON parser that supports Delphi 2009-10Seattle and the platforms Win32, Win64 and ARM Android (MacOS and iOS may work). Clone with GIT
or
This will get you the Json Data Objects repository. How to install
Features
UsageSimple example var
Obj: TJsonObject;
begin
Obj := TJsonObject.Parse('{ "foo": "bar", "array": [ 10, 20 ] }') as TJsonObject;
try
ShowMessage(Obj['foo']);
ShowMessage(IntToStr(Obj['array'].Count));
ShowMessage(IntToStr(Obj['array'].Items[0]));
ShowMessage(IntToStr(Obj['array'].Items[1]));
finally
Obj.Free;
end;
end; Filling and serializing JSON objects var
Obj, ChildObj: TJsonObject;
begin
Obj := TJsonObject.Create;
try
// easy access
Obj['foo'] := 'bar';
// normal (and faster) access
Obj.S['bar'] := 'foo';
// automatic array creation, Obj is the owner of 'array'
Obj.A['array'].Add(10);
Obj.A['array'].Add(20);
// automatic object creation, 'array' is the owner of ChildObj
ChildObj := Obj.A['array'].AddObject;
ChildObj['value'] := 12.3;
// automatic array creation, ChildObj is the owner of 'subarray'
ChildObj.A['subarray'].Add(100);
ChildObj.A['subarray'].Add(200);
ShowMessage(Obj.ToJSON({Compact:=}False));
finally
Obj.Free;
end; {
"foo": "bar",
"bar": "foo",
"array": [
10,
20,
{
"value": 12.3,
"subarray": [
100,
200
]
}
]
} Copying JSON objects with var
Obj, ClonedObj: TJsonObject;
begin
Obj := TJsonObject.ParseUtf8('{ "foo": [ "bar", {}, null, true, false, { "key": "value" } ] }') as TJsonObject;
try
ClonedObj := TJsonObject.Create;
try
// Make a copy of Obj
ClonedObj.Assign(Obj);
ShowMessage(ClonedObj.ToJSON(False));
finally
ClonedObj.Free;
end;
finally
Obj.Free;
end;
end; {
"foo": [
"bar",
{},
null,
true,
false,
{
"key": "value"
}
]
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论