/ / JSON POST usando AngularJS - angularjs, json, post

JSON POST usando AngularJS - angularjs, json, post

O AngularJS não está criando o JSON conforme desejado. Com código (abaixo), gera matriz (vapor serializado) mas não forma. ou seja estou obtendo

 {
data : "value",
date : "value"
}

Mas queria - JSON ou seja

{
"data" : "value",
"date" : "value"
}

O código para Angular para POST json é (snippet)

<script>
// Defining angularjs application.
var postApp = angular.module("postApp", []);
// Controller function and passing $http service and $scope var.
postApp.controller("postController", function($scope, $http) {
// create a blank object to handle form data.
$scope.user = {};
// calling our submit function.
$scope.submitForm = function() {
// Posting data to php file
$http({
method  : "POST",
url     : "user.php",
data    :JSON.stringify($scope.user),
headers : {"Content-Type": "application/json"}
})
.success(function(data) {
if (data.errors) {
// Showing some error which has to come from server
} else {
$scope.message = data.message; //make the json
}
});
};
});
</script>

O que devo fazer para obter o JSON e não o Array?

Respostas:

0 para resposta № 1

Se você quiser seus dados no formato JSON, você deve usar JSON.parse ();

$http({
method  : "POST",
url     : "user.php",
data    :JSON.parse($scope.user),
headers : {"Content-Type": "application/json"}
})

0 para resposta № 2

você tentou angular.toJson método?


0 para resposta № 3

Resolvido usando nada, isto é.

json: $ scope.user funciona ...