简体   繁体   中英

Accessing data value from JSON with no key value with AngularJS

I have a question regarding getting a data value from a JSON array that has no key value in Angular. I've seen plenty of examples getting the value out with a key, but I have not been able to figure this piece out.

The JSON that is returned from the API is quite complicated and looks like...

 [{"":796}] 

Its then assigned in the controller using this..

 $http({ method: 'GET', url: 'api/getnumassets' }).success(function(data) { $scope.numAssets = data; // response data }); 

Now when I use the snippet below to get the number out, I get the following value: {"":796} when I want it to display 796.

 <div class="number"> {{numAssets}} </div> <div class="desc"> {{'viewport.totalAssets' | translate}} </div> 

I've tried a number of different accessors on the numAssets expression but I have yet to have any luck. Any help would be much appreciated!

如果object是obj = {"":796} ,则可以通过以下方式访问其属性: obj['']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM