superobject

Store Array of Record in JSON

喜你入骨 提交于 2021-02-04 20:57:48
问题 How can an array of record be stored in JSON via SuperObject library. For example.. type TData = record str: string; int: Integer; bool: Boolean; flt: Double; end; var DataArray: Array[0..100] of TData; 回答1: Just use the superobject Marshalling TSuperRTTIContext program Project1; {$APPTYPE CONSOLE} {$R *.res} uses superobject, System.SysUtils; type TData = record str : string; int : Integer; bool : Boolean; flt : Double; end; TDataArray = Array [0 .. 100] of TData; procedure Test; var

delphi10的rest.json与system.json的踩坑

走远了吗. 提交于 2020-11-08 04:18:15
delphi10的rest.json与system.json的踩坑,足足一天多 delphi自带的rest.json,system.json不支持泛型,于是复杂一点的JSON,用继承类是可以实现的,结果多层的类封包时还是转换出错。不支持property的语法 找了一个X-superobject好像好一点,起码支持泛型,支持property语法。 https://github.com/onryldz/x-superobject 来源: oschina 链接: https://my.oschina.net/u/11596/blog/4707727

SuperObject cannot handle null string

六月ゝ 毕业季﹏ 提交于 2020-01-09 11:24:11
问题 Some JSON serializers return null for an empty string datafield, e.g. { "searchtext": null, "moretext": "contains something", "bookdate": 1377468000000, "empid": 12345, "listtype": 1 } I'm using SuperObject to create a ISuperObject: var FJSONRequest: ISuperObject; then FJSONRequest := SO(Request.Content); // Webservice request This returns an object with a string containing the text 'null' . Obviously this is because SuperObject does not care about the quotes ( "searchtext": a gives the same

SuperObject cannot handle null string

独自空忆成欢 提交于 2020-01-09 11:24:01
问题 Some JSON serializers return null for an empty string datafield, e.g. { "searchtext": null, "moretext": "contains something", "bookdate": 1377468000000, "empid": 12345, "listtype": 1 } I'm using SuperObject to create a ISuperObject: var FJSONRequest: ISuperObject; then FJSONRequest := SO(Request.Content); // Webservice request This returns an object with a string containing the text 'null' . Obviously this is because SuperObject does not care about the quotes ( "searchtext": a gives the same

使用Scheme模拟类和对象

自作多情 提交于 2019-12-29 20:34:03
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> a. 类和对象 函数定义可以解释为一个类,并且函数调用可以扮演对象的角色。换句话说,lambda表达式可以被视为类,而闭包可以被视为对象。 下面定义一个 point 类,lambda表达式将作为 point 类的实例对象句柄返回。这个对象句柄实际上是一个调度程序,它在给定message参数作为输入的情况下返回匹配的方法。 (define (point x y) (letrec ((getx (lambda () x)) (gety (lambda () y)) (add (lambda (p) (point (+ x (send 'getx p)) (+ y (send 'gety p))))) (type-of (lambda () 'point))) (lambda (message) (cond ((eq? message 'getx) getx) ((eq? message 'gety) gety) ((eq? message 'add) add) ((eq? message 'type-of) type-of) (else (error #f "Message not understood")))))) 在 add 方法中,我们使用 send 函数向对象发送消息。 send 函数仅查找方法,并使用

Delphi XE7: How to change a JSON value using System.JSON (versus SuperObject)

徘徊边缘 提交于 2019-12-22 18:26:17
问题 I need to load a JSON file, change a value and then write it back to disk. This is easy using SuperObject, but how do I do the same thing using the System.JSON unit? const PathToX = 'AllCategories.Category[0].subCategory[0].products[0].views.view[0].x'; var JsonFilename: string; JO: ISuperObject; // from the SuperObject unit JV: TJsonValue; // from the System.Json unit begin JsonFilename := ExtractFilePath(Application.ExeName)+'product.json'); // Using the SuperObject unit: JO := SO(TFile

Delphi / SuperObject - Accessing Subnodes

允我心安 提交于 2019-12-21 11:34:46
问题 I have the following JSON from my server: { "userid":"12", "username":"TestChar", "logged":"yes", "status":"Premium User", "areas":{ "SERVICEAREA_XX1":{ "id":"1", "area":"SERVICEAREA_XX1", "version":"3000", "usr_group":"0" }, "SERVICEAREA_XX2":{ "id":"2", "area":"SERVICEAREA_XX2", "version":"31000", "usr_group":"0" }, "SERVICEAREA_XX3":{ "id":"3", "area":"SERVICEAREA_XX3", "version":"2000", "usr_group":"1" } } } With SuperObjects i can get the count of "SERVICEAREA"'s with ob['areas']

Delphi Superobject, generic list to json

廉价感情. 提交于 2019-12-12 09:40:55
问题 I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject. TLogs = TObjectList<TLog>; TMyObject = class(TObject) private FLogs: TLogs; end; Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result. In this loop, there is a check on the TRttiFields FieldType. If it's nil, it skips the object. for f in Context.GetType(Value.AsObject.ClassType).GetFields do if f.FieldType <> nil then begin v :=

Serializing JSON object for an instance instantiated through a metaclass

*爱你&永不变心* 提交于 2019-12-11 11:52:50
问题 The SuperObject library has a generic method for serializing objects: type TSomeObject = class ... end; var lJSON : ISuperObject; lContext : TSuperRttiContext; lSomeObject : TSomeObject; begin lSomeObject := TSomeObject.Create; lContext := TSuperRttiContext.Create; lJSON := lContext.AsJson<TSomeObject>(lSomeObject); But now I'm dealing with metaclass instances. This is the object structure: TJSONStructure = class(TObject); TReqBase = class(TJSONStructure) private token: Int64; public end;

How to serialize JSON key containing dots (like e.g. IP address) with SuperObject?

你。 提交于 2019-12-08 19:47:42
问题 I'm trying to save JSON where IP is a key. Expected JSON result is: {"SnmpManagers":[{"10.112.25.235":162}]} The Delphi SuperObject code: const IpAddr = '10.112.25.235'; Port = 162; var tmp: TSuperObject; begin tmp := TSuperObject.Create; tmp.I[IpAddr] := Port; Json.A['SnmpManagers'].Add(tmp); end; SuperObject parses dots as path delimiters of a JSON object: {"SnmpManagers":[{"10":{"112":{"25":{"235":162}}}}]} How to save IP as a JSON key correctly with SuperObject ? 回答1: The solution is to