I have this service method
public object Get(EmployeeAccountsRequest request)
{
var list=userList.ToList();
var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(list);
return json;
}
Definition of EmployeeAccountRequest request class
[Route("/employeeaccount", "GET")]
public class AllUserAccountsRequest : IReturn<object>
{
public int projectNumber{ get; set; }
public int class{ get; set; }
}
which returns following JSON object.
[{"name": "Moroni", "allowance": 550, "paid": true},
{"name": "Tiancum", "allowance": 53, "paid": false},
{"name": "Jacob", "allowance": 27, "paid": false}]
Resource to get this data from service is as following:
angular.module('accService', ['ngResource']).factory('EmployeeAccount', function($resource) {
return $resource('/api/employeeaccount/:id', {}, {
get: {
method: 'GET',
},
query: {
method: 'GET',
},
update: {
method: 'PUT'
},
});
});
And trying to receive this value in controller
var app = angular.module('EmployeeApp');
app.controller('EmployeeAccountsController', function($scope, $http, EmployeeAccount) {
console.log(EmployeeAccount.query())
}
But i am not receiving the JSON object here. The above setup works fine if i return a list of array from my method.
So the question becomes why would a list of array is received properly and not a simple JSON object. Please let me know, if more information is needed.