我在使用POST和php REST服務器時遇到問題。 file_get_contents("php://input")
正在添加額外的引號。 這是造成json_decode(file_get_contents("php://input"),true)
到 失敗php file_get_contents(「php:// input」)加入引號
即 我張貼字符串化JSON
'{"someValue":0,"someOtherValue":1}'
PHP:
var_dump(file_get_contents("php://input"))
回報
string(173) "'{ "someValue" : 0, "someOtherValue" : "1"}'"
我PHP版本5.3.10是
要發佈的JSON,我目前使用的webstorm REST客戶端工具
Headers:
Accept: */*
Request Body:
Text: '{ "someValue" : 0, "someOtherValue" : "1"}'
我試圖從webstorm串去除外報價和它的工作I.E. { "someValue" : 0, "someOtherValue" : "1"}
我移動後最初使用擊中錯誤在角應用角ngResource
控制器
angular
.module('app.bookings')
.controller('BookAPuntController', BookAPuntController);
BookAPuntController.$inject(BookingServices);
function BookAPuntController(BookingServices) {
var data = {
someValue:0,
someOtherValue:1
};
BookingServices.save(JSON.stringify(data));
};
booking.dataservice.js
(function() {
'use strict';
angular
.module('app.data')
.factory('BookingServices', BookingServices);
BookingServices.$inject = ['$resource'];
/* @ngInject */
function BookingServices($resource) {
return $resource('rest/booking/:Id/:from/:to', null, {
'get': {method: 'GET', isArray: true},
});
}
})();
證明帖子是JSON字符串 – RiggsFolly
好代碼,你不應該跟單蜱''來輸出'。如果你不能修改它的輸出,那麼'preg_replace(「@(^'|'$)@」,'',file_get_contents(「php:// input」))' – DataHerder
你如何餵養JSON? –