I have an api that receives this json:
{
"instructions":[
{
"A":9,
"B":1,
"move":"moveover"
},
{
"A":8,
"B":1,
"move":"moveover"
}
],
"length":10,
"res":""
}
And the next one comes back to me:
{
"instructions": [
{
"A": 9,
"B": 1,
"move": "moveover"
},
{
"A": 8,
"B": 1,
"move": "moveover"
}
],
"length": 10,
"res": "Position [0] : 0Position [1] : 1 9 8Position [2] : 2Position [3] : 3Position [4] : 4Position [5] : 5Position [6] : 6Position [7] : 7Position [8] : Position [9] : "
}
I take the data from the following web page / form: What I do is save the values of A, B and movements in an array, for example:
//lo que tendria en memoria
var A=[1,3,5,8];
var B=[5,6,7,10];
var moves=[moveinto,moveover,pileover,pileinto];
//añadiendo los valores al array
$scope.addMove = function () {
A.push($scope.addA);
B.push($scope.addB);
moves.push($scope.addMov);
}
my question is how to assemble the json to be able to send it by post?
One idea I had was:
for (var i = 0; i < serverA.length; i++) {
objetoJson[i] = {
"instructions": [{
"A": serverA[i],
"B": serverB[i],
"move": serverMove[i]
}],
"length": $scope.blockLength,
"res": null
};
but it did not work for me, now what I did was send it manually and if it works for me:
json = {
"instructions": [{
"A": 9,
"B": 1,
"move": "moveover"
},
{
"A": 8,
"B": 1,
"move": "moveover"
}
],
"length": 10,
"res": ""
}
$http.post("http://localhost:56493/api/BlocksProblem", json)
.then(function (data) {
$scope.result = data;
}, function (response) {
$scope.result = response;
});
Could you tell me how to put my json together?