Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数据数组始终使用Angular.fromJson处理为字符串而不是数组_Javascript_Angularjs_Arrays_Angularjs Scope_Angularjs Http - Fatal编程技术网

Javascript 数据数组始终使用Angular.fromJson处理为字符串而不是数组

Javascript 数据数组始终使用Angular.fromJson处理为字符串而不是数组,javascript,angularjs,arrays,angularjs-scope,angularjs-http,Javascript,Angularjs,Arrays,Angularjs Scope,Angularjs Http,我有一个问题,我确实将字段形式设置为数组。示例:字段dfp_响应的兴趣为[]。所以,我必须将数据设置为数组,对吗?我在console.log中成功了。结果与->[5,6]类似,但当我使用angular.fromJson处理并使用$http发送时,我的参数dfp_的兴趣是字符串而不是数组。我错了吗?给我解决方案,还是我犯了一些错误 这是我在API中发送参数的过程 这是我对dfp_感兴趣的数据数组的示例 fromJson接受一个字符串参数,该参数表示您的代码应该是: var data = {user

我有一个问题,我确实将字段形式设置为数组。示例:字段dfp_响应的兴趣为[]。所以,我必须将数据设置为数组,对吗?我在console.log中成功了。结果与->[5,6]类似,但当我使用angular.fromJson处理并使用$http发送时,我的参数dfp_的兴趣是字符串而不是数组。我错了吗?给我解决方案,还是我犯了一些错误

这是我在API中发送参数的过程

这是我对dfp_感兴趣的数据数组的示例

fromJson接受一个字符串参数,该参数表示您的代码应该是:

var data = {username: 'newshubid', 
            data: { id: $scope.id, 
                    label: $scope.label, 
                    active: $scope.active,
                    parent_id: $scope.parent_id,
                    level: $scope.level,
                    meta_title: $scope.meta_title,
                    meta_description: $scope.meta_description,
                    meta_keyword: $scope.meta_keyword,
                    dfp_interest: $scope.tes }
           };

    var a = angular.fromJson(JSON.stringify(data));

你不明白什么是JSON。传入angular.fromJson的不是JSON.Variables插值$scope.id等,而是id和$scope.id不需要?@userpr JSON.stringify将为您执行此操作console.log是object而不是stringSo,xhr中的formData是object object,不能处理到API
$scope.tes = [5, 6];

$scope.testarray = $scope.tes.join("");
var data = {username: 'newshubid', 
            data: { id: $scope.id, 
                    label: $scope.label, 
                    active: $scope.active,
                    parent_id: $scope.parent_id,
                    level: $scope.level,
                    meta_title: $scope.meta_title,
                    meta_description: $scope.meta_description,
                    meta_keyword: $scope.meta_keyword,
                    dfp_interest: $scope.tes }
           };

    var a = angular.fromJson(JSON.stringify(data));