• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ahausladen/JsonDataObjects: JSON parser for Delphi 2009 and newer

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ahausladen/JsonDataObjects

开源软件地址:

https://github.com/ahausladen/JsonDataObjects

开源编程语言:

Pascal 100.0%

开源软件介绍:

Json Data Objects

This 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

> git clone [email protected]:ahausladen/JsonDataObjects.git

or

> git clone https://github.com/ahausladen/JsonDataObjects.git

This will get you the Json Data Objects repository.

How to install

  1. Clone the JsonDataObjects repository
  2. Add the JsonDataObjects.pas unit to your project.

Features

  • Fast dual JSON parser for parsing UTF8 and UTF16 without conversion
  • Automatic creation of arrays and objects
  • Easy access mode with implicit operators
  • Compact and formatted output modes
  • Variants support
  • Null can be auto-typecasted to a value type if JsonSerializationConfig.NullConvertsToValueTypes is set to True
  • Progress callback support for loading large JSON strings
  • Win32, Win64 and ARM Android support (MacOS and iOS may work)

Usage

Simple 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 Assign

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"
		}
	]
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap