我已经设置了Parse SDK,以及“Hello World!”功能运行正常。我现在尝试发送两个int(i1
& i2
)并返回总和。我需要知道的是:
1)如何发送变量
2)如何接收它们。将HashMap
从HashMap<String,Object>
更改为HashMap<Integer,Object>
会产生错误
ParseCloud函数(js)
Parse.Cloud.define("add", function(request,response)
{
var intA = 1;
var intB = 2;
var intC = intA + intB;
//var s = "Hello Add!";
//response.success(s);
response.success(intC);
});
Android方法,doAddition()
s1 = et1.getText().toString();
s2 = et2.getText().toString();
i1 = Integer.parseInt(s1);
i2 = Integer.parseInt(s2);
ParseCloud.callFunctionInBackground("add", new HashMap<Integer, Object>(), new FunctionCallback<Integer>()
{
@Override
public void done(Integer sum, ParseException e)
{
s3 = sum.toString();
et3.setText(s3);
}
});
上述Android方法出错:
The method callFunctionInBackground(String, Map<String,?>,
FunctionCallback<T>) in the type ParseCloud is not applicable for the
arguments (String, HashMap<Integer,Object>, new
FunctionCallback<Integer>(){})
答案 0 :(得分:0)
在调用Cloudfunction之前正确设置你的args(作为正确的javascript parms),然后将它们放入云功能中......
var mathArg1 = request.params.arg1;
var mathArg2 = request.params.arg2;
在JS中创建一个结果字段......
var mathResult = mathArg1 + mathArg2;
将结果作为JSON返回给客户端(在云接口中习惯了这一点!)
success: function(user) {
response.success(mathResult.toJSON());
},