Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
python读取Javascript数组的格式是什么?_Javascript_Arrays - Fatal编程技术网

python读取Javascript数组的格式是什么?

python读取Javascript数组的格式是什么?,javascript,arrays,Javascript,Arrays,我向充当API的python脚本发送参数。其中一个参数是Javascript数组。登录时,python显示为数组中的第一个索引 下面是我使用Angular JS的get请求: $http.get( apiBase + '/deals/timeline', { params: { api_key: $scope.settings.apiKey, start_date: startDate

我向充当API的python脚本发送参数。其中一个参数是Javascript数组。登录时,python显示为数组中的第一个索引

下面是我使用Angular JS的get请求:

    $http.get(
        apiBase + '/deals/timeline', {
            params: {
                api_key: $scope.settings.apiKey,
                start_date: startDate,
                interval: interval,
                amount: amount,
                fieldKeys: $scope.settings.fieldKeys
            }
        })
以下是我的python代码: 导入配置 导入json 导入请求

def api_deals_timeline(params):
    start_date = params.get('start_date')
    interval = params.get('interval')
    amount = params.get('amount')
    field_key = params.get('field_key')

    print(field_key)

    r = requests.get('url.com/?something={}&somelse={}'.format(start_date, interval))

    if r.status_code == 200:
        return json.loads(r.text)['data']
    else:
        return None
以下是我的apache日志中字段_key的打印语句:

【2014年8月14日星期四16:23:56】【错误】【u'add_time',u'won_time',u'lost_time',无】

下面是$scope.settings.fieldKeys的console.log:

[“输”、“赢”、“新”]


在JavaScript中,您需要将此列表作为JSON发送

JSON.stringify($scope.settings.fieldKeys);
在python中,需要将字段_key javascript数组转换为python列表。json库可以帮助您解决这个问题

json.loads(field_key)

显然,
lost
正在发生另一件事,它将成为
lost\u time
。另外,如果这真的只是一个列表,HTTP已经支持多次发送相同的参数。事实上,我是经过反复试验才发现这一点的。非常感谢。