PAS2JS: JSON suggestion

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PAS2JS: JSON suggestion

Free Pascal - General mailing list

IMHO, the TJSJSON external class definition is incorrect.

Currently, we have class function, if you want to use the stringify method, use this wierd way: TJSJSON.stringify( jsObject);

I think code that don't have mutual dependencies should be separate in units:

unit ECMA.Json;

interface

{$mode objfpc}
{$modeswitch externalclass}

type
  TKeyValueProcessor = function (Key: String; Value: JSValue): JSValue; 

  JJSON = class external name 'JSON'
  public
    function parse(Text: String): JSValue; overload;
    function parse(Text: String; Reviver: TKeyValueProcessor): JSValue; overload;
    function stringify(const Value: JSValue): String; overload;
    function stringify(const Value: JSValue; Replacer: TKeyValueProcessor): String; overload;
    function stringify(const Value: JSValue; Replacer: TKeyValueProcessor; Space: String): String; overload;
  end;

var
  JSON: JJSON; external name 'JSON';

implementation

end.

and use like this: JSON.stringify( JsonObject );



Sent from the Free Pascal - General mailing list archive at Nabble.com.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal