On Thu, 6 Aug 2015, Chris Moody wrote:
Hi all,
For my current project, I download a file from a server that contains JSON
code. I'm not sure how to read it into something that GetJSON is able to
handle.
My first thought was using TStrings, however not sure how to convert a
TString into TStream.
Any assistance would be much appreciated.
The following will read JSON and write all keys it finds
uses jsonparser, fpjson, sysutils, classes;
Var
F : TFileStream;
D : TJSONData;
E : TJSONEnum;
begin
D:=Nil;
F:=TFileStream.Create('myfile.json',fmOpenRead or fmShareDenywrite);
try
D:=GetJSON(F);
for E in D do
Writeln(E.Key, ' : ',E.Value.AsJSON);
Finally
D.free;
F.Free;
end;
end.
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal