使用方法POST时收到此错误。请帮帮我。未捕获的语法错误意外的令牌{在JSON中
angular_min.js:114 SyntaxError: Unexpected token { in JSON at position 71
at JSON.parse (<anonymous>)
at wc (angular_min.js:16)
at cc (angular_min.js:88)
at angular_min.js:89
at n (angular_min.js:7)
at hd (angular_min.js:89)
at c (angular_min.js:91)
at angular_min.js:126
at m.$eval (angular_min.js:141)
at m.$digest (angular_min.js:138)
我的代码: VAR JSON = {PARAMETER_NAME: “量”, “PARAMETER_VALUE”:$ scope.it.amount};
var arr=[];
arr.push(json);
$scope.object={formula:$scope.it.formula_saving_point};
$scope.companyTemp={company_id:com_id};
var url = API_URL + "cumulative_point_formula";
var cmd = "check_formula";
var jsonFinal = JSON.stringify({json_parameter: JSON.parse(JSON.stringify(arr)),
company: JSON.parse(JSON.stringify($scope.companyTemp)),
cumulative_point_formula: JSON.parse(JSON.stringify($scope.object))});
此日志jsonFinal
{"json_parameter":[{"parameter_name":"amount","parameter_value":"111111111"}],"company":{"company_id":40743},"cumulative_point_formula":{"formula":"amount/10000"}}
这是POST方法:
$http({
method: 'POST',
url: url,
data: $.param({cm: cmd, dt: jsonFinal}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (response) {
console.log("success");
});
如何修复这个bug?
你是否故意在这个问题中重复你的代码? – Claies
'JSON.parse(JSON.stringify($ scope.companyTemp))'呃...为什么? –
@Derek朕会功夫:老派克隆对象的方式。在很多浏览器中,它仍然是最快的方法 – slebetman