superobject

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

試著忘記壹切 提交于 2019-12-06 11:35:26
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.ReadAllText(JsonFilename)); WriteLn('The old value of "x" is ', JO[PathToX].AsString); WriteLn('Changing

Delphi Superobject, generic list to json

£可爱£侵袭症+ 提交于 2019-12-05 15:27:18
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 := f.GetValue(value.AsObject); result.AsObject[GetFieldName(f)] := ToJson(v, index); end My generic list

Delphi / SuperObject - Accessing Subnodes

时光毁灭记忆、已成空白 提交于 2019-12-04 04:37:21
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'].AsObject.count How can i now get access to the elements of the different "SERVICEAREA"'s? Thanks for your help

How to use SuperObject to invoke methods that uses an Object as parameter in Delphi?

江枫思渺然 提交于 2019-11-29 04:06:14
We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer I'd like to know how do I send a created object as a parameter. I tried to send it like LObjectList := TObjectList.Create; LSuperRttiCtx := TSuperRttiContext.Create; LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx); SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter); but inside MyMethod the LObjectList reference is lost. What am I doing wrong? The superobject library can be downloaded here It will

How to create JSON-file in Delphi using SuperObject lib?

不打扰是莪最后的温柔 提交于 2019-11-28 21:57:15
I'm using Delphi 2010 and superobject library. I have understand how to parse json-file, but I have no ideas how to create json? The algorithm is: Parsing JSON and load in TStringGrid Adding data Save all TStringGrid data to json. Need some example. Thanks. Code sample to feed following structure to JSON object, then save to file: (* { "name": "Henri Gourvest", /* this is a comment */ "vip": true, "telephones": ["000000000", "111111111111"], "age": 33, "size": 1.83, "adresses": [ { "adress": "blabla", "city": "Metz", "pc": 57000 }, { "adress": "blabla", "city": "Nantes", "pc": 44000 } ] } *)

SuperObject cannot handle null string

人走茶凉 提交于 2019-11-28 12:44:55
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 results as "searchtext": "a" ). Before I dive into the 980-line tokenizer routine, does any one have a

How to use SuperObject to invoke methods that uses an Object as parameter in Delphi?

北慕城南 提交于 2019-11-27 18:11:34
问题 We can use the SuperObject library to invoke methods of a certain object by its name and giving its parameters as a json string using the SOInvoker method like in this answer I'd like to know how do I send a created object as a parameter. I tried to send it like LObjectList := TObjectList.Create; LSuperRttiCtx := TSuperRttiContext.Create; LSuperObjectParameter := LObjectList.ToJson(LSuperRttiCtx); SOInvoke(MyInstantiatedObject, 'MyMethod', LSuperObjectParameter); but inside MyMethod the

SuperObject - Extract All

孤街浪徒 提交于 2019-11-27 15:23:01
问题 How to get ALL 'id' member values from a generic JSON . Without knowing structure of it . Because its very complex and it has a lot of sub objects. It has to loop through all the sub objects. Again for people that keep on asking where is the example JSON. My question is about how to extract a member value in my case "id" from any generic JSON that has this member inside . 回答1: If you don't know the structure of the JSON you receive from somewhere, it is important to note that JSON is "simply"

How to create JSON-file in Delphi using SuperObject lib?

天大地大妈咪最大 提交于 2019-11-27 14:05:16
问题 I'm using Delphi 2010 and superobject library. I have understand how to parse json-file, but I have no ideas how to create json? The algorithm is: Parsing JSON and load in TStringGrid Adding data Save all TStringGrid data to json. Need some example. Thanks. 回答1: Code sample to feed following structure to JSON object, then save to file: (* { "name": "Henri Gourvest", /* this is a comment */ "vip": true, "telephones": ["000000000", "111111111111"], "age": 33, "size": 1.83, "addresses": [ {