英文:
How to handle text/javascript API responses in Delphi (as application/json)?
问题
当我向iTunes搜索API发出请求时,返回的内容数据以JSON格式进行格式化,但响应的内容类型是text/javascript
而不是application/json
。
(the green one is from an API that is expected to work, but what I get from iTunes API is marked in red). 因此,Delphi的RESTDebugger接收到响应,但无法将其处理为有效的JSON('Content is not JSON')。
在IDE(Delphi 11)中,我也能够
Resp := TRequest.New.BaseURL('https://itunes.apple.com')
.Resource('search?term=' + EditSearch.Text)
.Accept('application/json')
.DataSetAdapter(MemTable)
.get;
这给我相同的200响应,但检索Resp.Content
不会得到任何内容,尽管它有内容(Resp.ContentLength
远大于零)。是否有办法将其转换为Delphi上可解析的JSON,以便我可以进一步处理它?
还尝试将上述命令中添加.ContentType('application/json')
,但没有成功。
这是一个示例请求的URL:
https://itunes.apple.com/search?media=music&term=talk
英文:
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
.
(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
答案1
得分: 0
根据Uwe的说法,应用11.3修复程序解决了问题。
英文:
As stated by Uwe, applying the 11.3 fix solved the problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论