我有一个返回JSON
数据的 php API,当我尝试JSON
从我的应用程序接收数据时,出现以下错误:
"Expected content type {(\n \"text/json\",\n \"application/json\",\n \"text/javascript\"\n)}, got text/html";
您可能会回答说 php API 没有返回有效的 JSON,好吧,我在 Json Lint 上检查了它,它是一个有效的 JSON,而且标头设置为JSON
header( 'Content-Type: text/json' );
echo '{"Response":'.json_encode($arr).'}';
我还检查了 MAMPmime.types
文件,它正确地包含了 JSON mime 类型。
我唯一怀疑的是,当我通过浏览器调用 API 时,我得到了预期的 JSON,但是当显示页面的源代码时,它在开头显示为 2 个空行。如下所示。
1-
2-
3- {"Response":[{"Product ID":"12037","Product Title":"RIng 14K Cloud 9","Product Description":"RIng 14K Cloud 9","Product Wholsale Price":"$255","Product Sale Price":"$460","Category Id":"55","Category Name":"Rings","Product Image":"http:\/\/192.163.1.87:8888\/xxxxxx\/wp-content\/uploads\/2012\/12\/150101.jpg","Product Sub Images":["http:\/\/192.163.1.87:8888\/xxxxx\/wp-content\/uploads\/2012\/12\/150101.jpg"],"SKU":"150101-50","Quantity":"1","Size":"50","Color":"Y","Manufacturer":"xxxxxx"},{"Product ID":"12039","Product Title":"Ring 14K Cloud 9","Product Description":"Ring 14K Cloud 9","Product Wholsale Price":"$255","Product Sale Price":"$460","Category Id":"55","Category Name":"Rings","Product Image":"http:\/\/192.163.1.87:8888\/xxxxx\/wp-content\/uploads\/2012\/12\/150101.jpg","Product Sub Images":["http:\/\/192.163.1.87:8888\/xxxxx\/wp-content\/uploads\/2012\/12\/150101.jpg"],"SKU":"150101-52","Quantity":"1","Size":"52","Color":"Y","Manufacturer":"xxxxxx"}]}
这是否与 php 代码或 MAMP 服务器中的任何内容有关?提前谢谢。