Chris Moody wrote 6 lines
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.
I do it like this, with TStringStream:
lStrings := TStringList.Create;
try
lStrings.LoadFromFile(AFile);
// Parse JSON data
lStream := TStringStream.Create(lStrings.Text);
lParser := TJSONParser.Create(lStream);
try
lParser.Strict := False;
lData := lParser.Parse;
finally
lParser.Free;
lStream.Free;
end;
Well, in my particular case I use TStringList because I pre-process the data, removing comments which are not allowed in JSON.
Felipe Monteiro de Carvalho