[fpc-pascal] Read JSON from file

Chris Moody inquiry at greensnakedesign.com
Fri Aug 7 09:40:57 CEST 2015


On 08/06/2015 07:01 PM, leledumbo wrote:
>> 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.
>
> Can't you figure out from the function interface:
> http://www.freepascal.org/docs-html/fcl/fpjson/getjson.html
>
>
Dentist.pas(56,18) Error: Incompatible type for arg no. 1: Got 
"TStringList", expected "TStream"

This is what I get when I use:

function ReadJSON (jsonfile, node:string) : string;
var
    json: tStringlist;
    J: TJSONData;
begin
   json:=TStringList.Create;
   json.loadfromfile(jsonfile);
   J:=GetJSON(json);    // Error is here.
   ReadJSON := J.FindPath(node).AsString;
end;

Does this mean my Lazarus / FPC is out of date? Or I'm using the wrong 
library or something?

Chris




More information about the fpc-pascal mailing list