java传递&使用解析云代码添加两个数字?
我已经设置了解析SDK,还有“你好,世界!”函数运行良好。我现在尝试发送两个int(i1
&;i2
)并返回总和。我需要知道的是:
1)如何发送变量
2)如何接收。因为将HashMap
从HashMap<String,Object>
更改为HashMap<Integer,Object>
会产生错误
解析云函数(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>(){})
# 1 楼答案
在调用Cloudfunction之前正确设置参数(作为正确的javascript参数),然后在CloudFunct中获取它们
在JS中创建一个结果字段
将结果以JSON的形式返回给客户端(在云接口中习惯此操作!)