On Sun, Dec 18, 2011 at 19:39, Michael Van Canneyt <mich...@freepascal.org>wrote:
> > > On Sun, 18 Dec 2011, ik wrote: > > Hello, >> >> I'm using FPC 2.6 (rc) x86_64 on Linux with JSONParser. >> >> I've written the following code: >> >> ----------------------- >> uses fpjson, jsonparser, SysUtils, classes; >> >> var >> parser : TJSONParser; >> json_file : TFileStream; >> >> begin >> json_file := TFileStream.Create('/tmp/test.**json', fmOpenRead); >> json_file.position := 0; >> parser := TJSONParser.create(json_file); >> writeln('JSON: ', parser.Parse.AsJSON); >> > > You are not freeing the result of the parse operation ? > > The user is responsible for freeing the result of .parse() > > So you must do > > Var > D: TJSONData; > > parser := TJSONParser.create(json_file); > D:=Parser.parse; > writeln('JSON: ', D.AsJSON); > D.free; // Free result of parse. > > And while you're at it, you must always use try/finally blocks. > Otherwise any exception (an error in the json) will result in your code > not freeing the file stream or parser instance. > The fruit of this questions: http://translate.google.com/translate?sl=auto&tl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fidkn.wordpress.com%2F2011%2F12%2F19%2Fworking-withh-json-using-fpc%2F&act=url:) They translated very good but not perfect as you'll see. And they destroyed the source code there. I might upload it to github or something. > > Michael. > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > Ido
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal