0

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.

2
  • are you injecting employeeAccount? Commented Feb 16, 2015 at 19:28
  • Can you inspect the request using the Network tab of the Dev Tools console? See what the raw response looks like. You're sure that your server is returning valid JSON? Commented Feb 17, 2015 at 2:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.