2

我需要使用 AngularJS 的 $http 调用 Parse RESTFUL API 来检索特定数据,Parse 允许我这样做的唯一方法是将“--data-urlencode where={"storeId":2}" 发送到 curl 调用.

curl -X GET -H "X-Parse-Application-Id:ApplicationId" -H "X-Parse-REST-API-Key: ApiKey" -G --data-urlencode 'where={"storeId":2}' https://api.parse.com/1/classes/Stores/

见这里:https ://parse.com/docs/rest#queries-arrays

我可以使用终端返回 JSON 结果,但不能使用 $http()。任何人都知道我如何将“--data-urlencode where={"storeId":2}" 注入 AngularJS $http() 或 $resource() 方法?

见这里:http://docs.angularjs.org/api/ng.$http

4

1 回答 1

5

查看 parse api 的 python 引用,我想where={"storeId":2}可以将其作为查询参数附加(如果不访问 parse api,我无法测试它)。从参考:

params = urllib.urlencode({"where":json.dumps({
   "arrayKey": 2
})})

在 AngularJS 中,您可以使用's对象param中的键添加查询参数:$httpconfig

var req = $http({
    params: {
        where: {storeId: 2},
    },
    headers: {
        'X-Parse-Application-Id': 'ApplicationID',
        'X-Parse-REST-API-Key': 'ApiKey'
    }
    //... other params, like URL
});

params.where值将自动转换为 JSON 字符串。我不确定查询参数是否默认获取 URL 编码,如果没有,则 JSON 手动对其进行编码并应用该encodeURIComponent函数。

于 2013-06-19T19:17:31.030 回答