JsonDataObjects
JsonDataObjects copied to clipboard
TJsonBaseObject.ParseFromFile fails on IIS
This is a very strange bug - it only manifests itself under our ISAPI application running on IIS (Windows Server) but not on IIS (Windows 10 professional)
Anyway, making a call to TJsonBaseObject.ParseFromFile returns nil in the error case. Changing the implementation code as below fixes the problem and the text is parsed correctly into a JSON object.
class function TJsonBaseObject.ParseFromFile(const FileName: string; Utf8WithoutBOM: Boolean{$IFDEF SUPPORT_PROGRESS}; AProgress: PJsonReaderProgressRec{$ENDIF}): TJsonBaseObject;
var
Stream: TFileStream;
begin
Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
// add this line
Stream.Seek(0, soBeginning);
Result := ParseFromStream(Stream, nil, Utf8WithoutBOM{$IFDEF SUPPORT_PROGRESS}, AProgress{$ENDIF});
finally
Stream.Free;
end;
end;