higale 1 年之前
父节点
当前提交
dcc7da8a26
共有 3 个文件被更改,包括 66 次插入44 次删除
  1. 40 24
      README.md
  2. 24 18
      README_zh.md
  3. 2 2
      rjson.pas

+ 40 - 24
README.md

@@ -54,25 +54,28 @@
 - `Format` Outputs a formatted JSON string without encoding.
 - `ParseJSONValue` Loads data from a string.
 - `LoadFromFile` Loads data from a file.
-- `SaveToFile` Saves to a file.
-
-        // Saves formatted JSON data to a file.
-        procedure SaveToFile(
-            const AFileName: string; // File name.
-            AIndentation: Integer;   // Number of spaces for indentation.
-            AWriteBOM: boolean = False // Whether to write BOM marker; defaults to False.
-        );
-
-        // Saves encoded JSON data to a file.
-        procedure SaveToFile(
-            const AFileName: string;
-            AEncodeBelow32: boolean = true; // Whether to encode ASCII characters less than 32; defaults to True.
-            AEncodeAbove127: boolean = true; // Whether to encode ASCII characters greater than 127; defaults to True.
-            AWriteBOM: boolean = False // Whether to write BOM marker; defaults to False.
-        );
+- `SaveToFile` Saves formatted JSON data to a file.
+```pascal
+procedure SaveToFile(
+    const AFileName: string; // File name.
+    AIndentation: Integer;   // Number of spaces for indentation.
+    AWriteBOM: boolean = False // Whether to write BOM marker, default is False.
+);
+```
+- `SaveToFile` Saves encoded JSON data to a file.
+```pascal
+procedure SaveToFile(
+    const AFileName: string;
+    AEncodeBelow32: boolean = true; // Whether to encode ASCII characters below 32, default is True.
+    AEncodeAbove127: boolean = true; // Whether to encode ASCII characters above 127, default is True.
+    AWriteBOM: boolean = False // Whether to write BOM marker, default is False.
+);
+```
 
 ## Example:
 ```pascal
+uses rjson;
+
 procedure TFormMain.btnTestClick(Sender: TObject);
 var
   RJ, RJ1: TRJ;
@@ -83,29 +86,42 @@ begin
   RJ.S['title2'] := '世界,你好!';
   RJ.Items['title3'] := 'Good';
   RJ['a.num'] := 1;
-  RJ['a.hah'] := false;
+  RJ['a.haha'] := false;
   RJ['b[2]'] := 505;
   RJ['b[0]'] := 'first';
   RJ['good'] := True;
+
   RJ1 := RJ['c'];
   RJ1['c1'] := 1.1;
   RJ1['c2[2]'] := 2.33;
+
   with RJ['x'] do
   begin
-    items[1] := 100;
-    items[2] := '202';
+    Items[1] := 100;
+    Items[2] := '202';
   end;
+
   with RJ['y'] do
   begin
-    items['ya'] := 'y1';
-    items['yb'] := -2;
+    Items['ya'] := 'y1';
+    Items['yb'] := -2;
   end;
-  Memo1.Text := RJ.Format;
+
+  Memo1.Lines.Add('ToString:');
+  Memo1.Lines.Add(RJ.ToString);
+  Memo1.Lines.Add('ToJSON:');
+  Memo1.Lines.Add(RJ.ToJSON);
+  Memo1.Lines.Add('Format:');
+  Memo1.Lines.Add(RJ.Format);
+
   Memo1.Lines.Add('-----------------------------------------------------------');
+
   fTemp := RJ['c.c2[3]'];
+  Memo1.Lines.Add('fTemp = ' + fTemp.ToString);
+
+  fTemp := RJ['c.none[3]'].ToFloat(-100);
   Memo1.Lines.Add('fTemp:' + fTemp.ToString);
-  fTemp := RJ['c.c3[3]'].ToFloat(-100);
-  Memo1.Lines.Add('fTemp:' + fTemp.ToString);
+
   Memo1.Lines.Add(RJ['a.num'].ToStr('a.num not exist'));
   Memo1.Lines.Add(RJ['none'].ToFloat(-1).ToString);
   Memo1.Lines.Add(RJ['none.a3'].ToStr('none.a3 not exist'));

+ 24 - 18
README_zh.md

@@ -54,26 +54,28 @@
 - `Format` 输出格式化的 JSON 字符串,不做编码。
 - `ParseJSONValue` 从字符串加载数据。
 - `LoadFromFile` 从文件加载数据。
-- `SaveToFile` 保存到文件。
-
-        // 将格式化过的JSON数据保存到文件。
-        procedure SaveToFile(
-            const AFileName: string; // 文件名
-            AIndentation: Integer;   // 缩进的空格数
-            AWriteBOM: boolean = False // 是否写入BOM标记,默认为False。
-        );
-
-        //以编码过的JSON数据保存到文件。
-        procedure SaveToFile(
-            const AFileName: string;
-            AEncodeBelow32: boolean = true; // 是否编码ASCII码小于32的字符,默认为True。
-            AEncodeAbove127: boolean = true; // 是否编码ASCII码大于127的字符,默认为True。
-            AWriteBOM: boolean = False // 是否写入BOM标记,默认为False。
-        );
-
+- `SaveToFile` 将格式化过的JSON数据保存到文件。
+```pascal
+procedure SaveToFile(
+    const AFileName: string; // 文件名。
+    AIndentation: Integer;   // 缩进的空格数
+    AWriteBOM: boolean = False // 是否写入BOM标记,默认为False
+);
+```
+- `SaveToFile` 将编码过的JSON数据保存到文件。
+```pascal
+procedure SaveToFile(
+    const AFileName: string;
+    AEncodeBelow32: boolean = true; // 是否编码ASCII码小于32的字符,默认为True。
+    AEncodeAbove127: boolean = true; // 是否编码ASCII码大于127的字符,默认为True。
+    AWriteBOM: boolean = False // 是否写入BOM标记,默认为False。
+);
+```
 
 ## 示例:
 ```pascal
+uses rjson;
+
 procedure TFormMain.btnTestClick(Sender: TObject);
 var
   RJ, RJ1: TRJ;
@@ -84,23 +86,27 @@ begin
   RJ.S['title2'] := '世界,你好!';
   RJ.Items['title3'] := 'Good';
   RJ['a.num'] := 1;
-  RJ['a.hah'] := false;
+  RJ['a.haha'] := false;
   RJ['b[2]'] := 505;
   RJ['b[0]'] := 'first';
   RJ['good'] := True;
+
   RJ1 := RJ['c'];
   RJ1['c1'] := 1.1;
   RJ1['c2[2]'] := 2.33;
+
   with RJ['x'] do
   begin
     items[1] := 100;
     items[2] := '202';
   end;
+
   with RJ['y'] do
   begin
     items['ya'] := 'y1';
     items['yb'] := -2;
   end;
+
   Memo1.Text := RJ.Format;
   Memo1.Lines.Add('-----------------------------------------------------------');
   fTemp := RJ['c.c2[3]'];

+ 2 - 2
rjson.pas

@@ -1,7 +1,7 @@
 {
   TRJ - JSON Simple Read and Write
-  - v0.9.4
-  - 2024-09-09 by gale
+  - v0.9.5
+  - 2024-09-10 by gale
   - https://github.com/higale/RJSON
 }
 unit rjson;