【问题标题】:Resolving a python array wrapped in Json with Angular.js $resource使用 Angular.js $resource 解析包裹在 Json 中的 python 数组
【发布时间】:2016-04-13 19:15:11
【问题描述】:

我正在使用 webapp2 和 Angular 的 $resource,我很难完成这项工作并在我的控制器中从 JSON 格式解析我的数据数组。

在我的python处理程序中,JSON格式的数组包装如下:

self.response.write(json.encode(self.getVertices()))

这是我在 Angular 中的服务代码:

angular.module('myPage').service('onServices',['$resource','$q', 
function($resource,$q){
   this.getMesh = function(){
   var Mesh = $resource('/context/actors/one',
   {}, {get: {method:'GET', isArray:true,responseType:'json'}})
   return Mesh.get().$promise.then(function(data) {
               one = data
               return one})   
}
}]);

我的控制器代码是这样的:

$scope.bck =  onServices.getMesh();

当我在服务中记录“数据”时,它显示为一系列“资源”,每个资源都包含一行数组。当我在控制器中记录数据时,它仍然是“承诺”格式,其中包含一系列“资源”(数组行)。我可以看到 Promise 中的数据,但我没有看到预期格式的数据,即 JSON。谢谢。

【问题讨论】:

    标签: angularjs json rest controller webapp2


    【解决方案1】:

    当你调用 python 部分时你会得到 JSON 吗?你试过这个Python JSON docs

    self.response.headers['content-type'] = 'text/plain'
    self.response.write(json.dumps(self.getVertices()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 2015-06-17
      • 1970-01-01
      相关资源
      最近更新 更多