0
我有一個Laravel RESTful API設置,需要以JSON格式將數據返回到我的子域之一(因此不在Laravel應用程序本身內)的應用程序。如何僅從Laravel 4 REST API返回JSON響應?
在REST我回國,如:
return \Response::json(array(
"status" => "success",
"type" => "client",
"message" => "Nothing to see here!"
));
在我的課上的子域的應用程序,我只是想回到這個響應於查看打印輸出進行測試。
我希望,我剛剛回來JSON,但是當我做一個簡單:
echo $resp;
我什麼也沒得到
如果我做了:
print_r($resp);
或
json_decode($resp);
我得到:
HTTP/1.1 200 OK
Server: nginx/1.6.2
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.4.35
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Date: Sat, 06 Dec 2014 04:18:15 GMT
Set-Cookie: laravel_session=eyJpdiI6Ik5DdDFGK2tJQ3ZCVkJPQnRtZHRaU2c9PSIsInZhbHVlIjoiT2tXSTJWYzRKUXZncG9NOFZBYkhOUTZRaUg1c3NmUXlHTjF5bzYyaTZRYUY4S3VBMEdwdjdwdXNUNHkwblppV1I5YUFsY2dodGNyRHh5SmZYeGFjcWc9PSIsIm1hYyI6Ijc0Mzg3MGNlNTBiYTEyNTE3MzNhZDVjNjUzNzMwNzk0ZTMwN2MwYmFiNDIyMGE0N2MyNTQxMDNlMDdiOGFmOTQifQ%3D%3D; expires=Sat, 06-Dec-2014 06:18:15 GMT; path=/; httponly
{"status":"success","type":"client","message":"Nothing to see here!"}
我不希望所有的頭文件都在我的回覆中。或者我正在接收並試圖錯誤地解析它。我在這裏做錯了什麼?
試試這個http://tekina.info/creating-general-api-responder-laravel/ – 2018-01-13 19:18:36