JSON序列——保存修改数据2
procedure TForm1.Button7Click(Sender: TObject); begin var delta: TynJsonDelta := TynJsonDelta.Create('tunit'); var delta2: TynJsonDelta := TynJsonDelta.Create('tgoods'); var deltas: TynJsonDeltas := TynJsonDeltas.Create; try delta.Insert('{"unitid":"13","unitname":"人"}'); delta.Delete('{"unitid":"66","unitname":"国"}'); delta.Update('{"unitid":"11","unitname":"中"}', '{"unitid":"11","unitname":"个"}'); delta2.Insert('{"goodsid":"123456","goodsname":"咏南中间件"}'); deltas.Add(delta.Text); deltas.Add(delta2.Text); Memo1.Text := deltas.Text; finally delta.Free; delta2.Free; deltas.Free; end; end;
生成JSON:
{ "deltas": [ { "table": "tunit", "rows": [ { "action": "insert", "current": { "unitid": "13", "unitname": "人" } }, { "action": "delete", "original": { "unitid": "66", "unitname": "国" } }, { "action": "modify", "current": { "unitid": "11", "unitname": "中" }, "original": { "unitid": "11", "unitname": "个" } } ] }, { "table": "tgoods", "rows": [ { "action": "insert", "current": { "goodsid": "123456", "goodsname": "咏南中间件" } } ] } ] }