system.json

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

How to pretty print with System.Json?

会有一股神秘感。 提交于 2019-12-06 06:59:39
问题 Using the new System.Json from 4.5 or the equivalent System.Json for 4.0 from Nuget how do you format the output so it is indented ans spaced in a more readable form? So this dynamic jsonObj = new JsonObject(); jsonObj.firstName = "John"; jsonObj.lastName = "Smith"; Debug.WriteLine((string)jsonObj.ToString()); Outputs this {"firstName":"John","lastName":"Smith"} When I want this { "firstName": "John", "lastName": "Smith" } 回答1: For future reference, the System.Json library in .NET 4.5 (And 4

How to pretty print with System.Json?

笑着哭i 提交于 2019-12-04 12:56:46
Using the new System.Json from 4.5 or the equivalent System.Json for 4.0 from Nuget how do you format the output so it is indented ans spaced in a more readable form? So this dynamic jsonObj = new JsonObject(); jsonObj.firstName = "John"; jsonObj.lastName = "Smith"; Debug.WriteLine((string)jsonObj.ToString()); Outputs this {"firstName":"John","lastName":"Smith"} When I want this { "firstName": "John", "lastName": "Smith" } For future reference, the System.Json library in .NET 4.5 (And 4.5 only, not Silverlight) has the JsonSaveOptions enumerator, so you can call ToString(JsonSaveOptions