Giter Site home page Giter Site logo

json4delphi's People

Contributors

goncons avatar hafedh-trimeche avatar rilyu avatar vincentgsell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

json4delphi's Issues

Stringify performance

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.

Error parsing Json [White Spaces]

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.

Object To Json representation problem

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


Object To Json

fazendo uso em lazarus ao usar o _objecttojson retorna apenas '{}' como fazer para funcionar em lazarus ?

Json.Stringify in DXE7 not working ?

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.

GLB_JSON_STD_DECIMALSEPARATOR

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.