Search code examples
jsonrestdelphidelphi-11-alexandria

How to handle text/javascript API responses in Delphi (as application/json)?


When I make a request to the iTunes search API, the returned content data is formatted as a JSON, but the response's content-type is text/javascript instead of application/json.

:Headers

(the green one is from an API that is expected to work, but what I get from iTunes API is marked in red). Thus, Delphi's RESTDebugger receives the response but cannot process it as a valid JSON ('Content is not JSON').

On the IDE (Delphi 11) I am also able to

var Resp: IResponse;
Resp := TRequest.New.BaseURL('https://itunes.apple.com')
          .Resource('search?term=' + EditSearch.Text)
          .Accept('application/json')
          .DataSetAdapter(MemTable)
          .get;

which gives me that same 200 response, but retrieving Resp.Content gets me nothing despite it has content (Resp.ContentLength is much greater than zero). Is there a way to convert it to some parseable JSON on Delphi so I can make further processing to it? Also tried adding .ContentType('application/json') to the command above with no success.

Here is the URL for a sample request: https://itunes.apple.com/search?media=music&term=talk


Solution

  • As stated by Uwe, applying the 11.3 fix solved the problem.