javascript - Using Web API JSON Response from AngularJS - Error: expected and array but got an object -


i have web api returning response in json, in format:

{   "email": "john@google.com",   "password": null,   "accesslevel": 2 } 

i trying access accesslevel field within response, getting angular error:

error in resource configuration action `query`. expected response contain array got object (request: http://localhost:51608/api/userrole?email=john@google.com...) 

this angular resource code (below), added isarray false attempt solve issue:

function userroleresource($resource, appsettings) {     return $resource(appsettings.serverpath + "/api/userrole?email=:email", { email: '@email' },     {         get: {             method: 'get',             isarray: false         }     }); } 

and how attempting use data:

userroleresource.query({ email: vm.userdata.email },    function (data) {       vm.userdata.accesslevel = data.accesslevel; }); 

you're specifying 'get' function not array, you're using 'query' function.

try this:

userroleresource.get({ email: vm.userdata.email },     function (data) {         vm.userdata.accesslevel = data.accesslevel; }); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -