在后台作业解析中输入"\" [英] '\' entering in input in background job parse
问题描述
当我运行此后台作业时,这就是我得到的日志.
When I run this background job, this is the log I am getting.
I2015-06-05T11:17:37.360Z]v163: Ran job DeleteAccount with:
Input: "{\"username\":\"9369190589\"}"
request.params.username是未定义的,因为存在'\'.因此,我无法访问用户名.如何从工作中访问用户名
request.params.username is undefined because '\' is present. So I am unable to access username. How can I access username from the job
更新: 这是我正在尝试的代码部分
Update: Here is the part of code I'm trying
Parse.Cloud.job("DeleteAccount", function(request, response){
var id = request.object.get("username");
console.log("id = " + id);
});
这是错误: I2015-06-05T11:06:31.839Z] v163:使用以下命令运行作业DeleteAccount:
Here is the error: I2015-06-05T11:06:31.839Z]v163: Ran job DeleteAccount with:
输入:"{\" id \:\" 9369190589 \}"
Input: "{\"id\":\"9369190589\"}"
失败:TypeError:无法调用未定义的方法"get"
Failed with: TypeError: Cannot call method 'get' of undefined
甚至request.params.username也不起作用
And even request.params.username is also not working
推荐答案
由于我没有足够的声誉来发表评论,因此我将在此处做出贡献.
As I don't have enough reputation to comment, I will contribute here.
我和你有同样的问题.另外,我注意到,当使用REST请求调用作业时,输入日志将打印为
I have the same problem as you. In addition, I noticed that when calling the job with a REST request, the input log is printed as
I2015-06-12T16:18:16.285Z]
I2015-06-12T16:18:16.503Z]v44: Ran job XXX with:
Input: {"api":"2oil4z6k","name_asset":"SX5E"}
Result: undefined
REST请求的参数声明为 -d'{"api":"2oil4z6k","name_asset":"SX5E"}'
The parameter fo the REST request is declared as -d '{"api":"2oil4z6k","name_asset":"SX5E"}'
当使用计划的云作业"调用该作业时,日志将打印为
Whereas when the job is called with the Scheduled Cloud Job the log is printed as
I2015-06-12T16:23:27.259Z]
I2015-06-12T16:23:27.432Z]v44: Ran job XXX with:
Input: "{\"api\":\"2oil4z6k\", \"name\":\"SX5E\"}"
Failed with: An error has occurred
此参数在参数输入中声明为{"api":"2oil4z6k","name":"SX5E"}
This thime the the parameter is declared in the parameter input as {"api":"2oil4z6k", "name":"SX5E"}
因此,似乎计划的云作业"正在转义JSON对象中的每个字符串.
So it seems like the Scheduled Cloud Job is escaping every string in the JSON object.
解决方案是在request.params上调用JSON.parse()
The solution is to call JSON.parse() on the request.params
data = JSON.parse(request.params);
希望有帮助!
这篇关于在后台作业解析中输入"\"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!