RAD Studio 10.2.3 测试√
procedure TForm1.Button_SetJSONDataClick(Sender: TObject);
var
// uses System.JSON;
mJSON, mTempJSON: TJSONObject;
mJSONArray: TJSONArray;
begin
mJSON := TJSONObject.Create;
mJSONArray := TJSONArray.Create;
try
mJSON.AddPair('TestDate', datetimetostr(now)); // 添加第一条数据
mJSON.AddPair('UserList', mJSONArray); // 第二条数据的值是一个 JSON 数组
mTempJSON := TJSONObject.Create; // 创建一个临时的 JSON 对象
mTempJSON.AddPair('UserName', 'xiaoyin01'); // 为这个临时的 JSON 对象赋值
mTempJSON.AddPair('Pass', '123');
mJSONArray.Add(mTempJSON); // 把临时的 JSON 对象添加到 JSON 数组中
mTempJSON := TJSONObject.Create;
mTempJSON.AddPair('UserName', 'xiaoyin02');
mTempJSON.AddPair('Pass', '456');
mJSONArray.Add(mTempJSON);
Memo1.Lines.Add(mJSON.ToJSON); // 打印 JSON 数据
finally
mJSON.Free;
end;
end;
一点点笔记,以便以后翻阅。