[fpc-pascal] Read JSON from file

Chris Moody inquiry at greensnakedesign.com
Fri Aug 7 10:49:02 CEST 2015



On 08/07/2015 12:46 AM, Michael Van Canneyt wrote:
>
>
> On Fri, 7 Aug 2015, Chris Moody wrote:
>
>> 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?
>
> GetJSON doesn't allow a Tstrings argument. Where did you get that from ?
>
> Please check the sample code I sent.
>
> Michael.

I do apologize, I was looking at a web page and found I didn't read it 
well enough. Thanks for your code suggestion, I will see about making it 
work for me.

Chris



More information about the fpc-pascal mailing list