#1 2016-03-18 21:39:58

witya
Member
Registered: 2015-09-25
Posts: 5

Patch json for boolean type support

json.org

value.gif

--- SynCrossPlatformJSON.pas    2016-03-17 15:44:50.000000000 +0700
+++ SynCrossPlatformJSON_patch.pas    2016-03-19 15:17:54.000000000 +0700
@@ -803,6 +803,12 @@
     result := ValueToJSON(PVariant(TVarData(Value).VPointer)^) else
   if TVarData(Value).VType<=varNull then
     result := 'null' else
+  if TVarData(Value).VType=varBoolean then begin
+    if Value then
+      result := 'true'
+    else
+      Result := 'false'
+  end else       
   if VarIsOrdinal(Value) then begin
     I64 := Value;
     result := IntToStr(I64);
@@ -835,7 +841,7 @@
   {$endif}
   vtPWideChar:  result := string(VPWideChar);
   vtWideChar:   result := string(VWideChar);
-  vtBoolean:    if VBoolean then result := '1' else result := '0';
+  vtBoolean:    if VBoolean then result := 'true' else result := 'false';
   vtInteger:    result := IntToStr(VInteger);
   vtInt64:      result := IntToStr(VInt64^);
   vtCurrency:   DoubleToJSON(VCurrency^,result);


Sample Test

doc:=JSONVariant('{}');
doc.Name:='John';
doc.Active:=True;
println(doc)

result before path
{"Name":"John","Active":-1}

result after patch
{"Name":"John","Active":true}

Offline

Board footer

Powered by FluxBB