rilyu / json4delphi Goto Github PK
View Code? Open in Web Editor NEWJSON for Delphi, support for older versions of Delphi (6 or above)
JSON for Delphi, support for older versions of Delphi (6 or above)
Hello,
Would TStringStream be used to enhance writing performance instead of concatenating Json elements?
function TJsonArray.Stringify: String;
var
I: Integer;
Item: TJsonValue;
begin
Result := '[';
for I := 0 to FList.Count - 1 do
begin
Item := TJsonValue(FList[I]);
if I > 0 then Result := Result + ',';
Result := Result + Item.Stringify;
end;
Result := Result + ']';
end;
function TJsonObject.Stringify: String;
var
I: Integer;
Item: TJsonPair;
begin
Result := '{';
for I := 0 to FList.Count - 1 do
begin
Item := TJsonPair(FList[I]);
if I > 0 then Result := Result + ',';
Result := Result + Item.Stringify;
end;
Result := Result + '}';
end;
Best regards.
Hello,
Thank you for providing this library.
AnalyzeJsonValueType raised an exception when Json text contains White Spaces (<#32: #10, #13, #9, ...)
This function would be:
function TJsonBase.AnalyzeJsonValueType(S:String):TJsonValueType;
var
Len : Integer;
Number : Extended;
begin
S := Trim(S); /////////////////////////////
Result := jvNone;
Len := Length(S);
if Len >= 2 then
begin
if (S[1] = '{') and (S[Len] = '}') then Result := jvObject
else if (S[1] = '[') and (S[Len] = ']') then Result := jvArray
else if (S[1] = '"') and (S[Len] = '"') then Result := jvString
else if SameText(S, 'null') then Result := jvNull
else if SameText(S, 'true') or SameText(S, 'false') then Result := jvBoolean
else if FixedTryStrToFloat(S, Number) then Result := jvNumber;
end
else if FixedTryStrToFloat(S, Number) then Result := jvNumber;
end;
Best regards.
Hello,
This code
unit Main;
interface
uses
Winapi.Windows, REST.JSON, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
JsonsUtilsEx;
type
TForm1 = class(TForm)
Memo1: TMemo;
ObjectBtn: TButton;
procedure ObjectBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TJObject=class
private
FP1 : Integer;
FP2 : TBytes;
FP3 : string;
FP4 : TDateTime;
published
property P1 : Integer read FP1 write FP1;
property P2 : TBytes read FP2 write FP2;
property P3 : string read FP3 write FP3;
property P4 : TDateTime read FP4 write FP4;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ObjectBtnClick(Sender: TObject);
var
O : TJObject;
sJson : string;
begin
O := TJObject.create;
O.P1 := 11;
O.P2 := [3,2,1];
O.P3 := 'String';
O.P4 := now;
sJson := __ObjectToJson(O);
Memo1.Lines.Add(sJson);
O.P2 := [];
__jsonToObject(sJson,TObject(O));
sJson := __ObjectToJson(O);
Memo1.Lines.Add(sJson);
FreeAndNil(O);
end;
initialization
ReportMemoryLeaksOnShutdown := True;
finalization
end.
generated this Json:
{
"P1" : 11 ,
"P2" : [ -1761541629,-2139084140,0 ] ,
"P3" : "String" ,
"P4" : "2021-01-03T21:58:55.055Z"
}
The output would be:
{
"P1" : 11 ,
"P2" : [ 3,2,1 ] ,
"P3" : "String" ,
"P4" : "2021-01-03T21:58:55.055Z"
}
Line 395 in dba8a9d
fazendo uso em lazarus ao usar o _objecttojson retorna apenas '{}' como fazer para funcionar em lazarus ?
Json := TJson.Create();
Json['field6'].AsString := 'hello world';
writeln(Json.Stringify());
This simple code should produce a string
{"field6" : "hello world"}
??
If so it is not what is happening using Delphi XE7. An empty string is the result.
Hi,
JsonsUtils_GLB_DECIMALSEPARATOR would be replaced by GLB_JSON_STD_DECIMALSEPARATOR and not the opposite:
function FixedTryStrToFloat(const S: string; out Value: Extended): Boolean;
var
FixedS: string;
begin
if JsonsUtils_GLB_DECIMALSEPARATOR = GLB_JSON_STD_DECIMALSEPARATOR then
begin
Result := TryStrToFloat(S, Value);
end
else
begin
FixedS := StringReplace( S,
JsonsUtils_GLB_DECIMALSEPARATOR,
GLB_JSON_STD_DECIMALSEPARATOR,
[rfReplaceAll]);
Result := TryStrToFloat(FixedS, Value);
end;
end;
Best regards.
I made the library scriptable to maXbox4 engine, runs fine now:
http://www.softwareschule.ch/examples/covid2.txt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.