在使用参数作为HashMap发送云代码请求时遇到问题。有趣的是,如果我发送一个带有空参数的请求,它的工作完全正常。 这是我的请求代码(更新了ishmaelMakitla'答案):
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", new String[]{"hey"});
ParseCloud.callFunctionInBackground("", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
@Override
public void done(Object object, ParseException e) {
Log.v("26", "" + object);
if (e != null) {
Log.v("27", "" + e);
}
for (Object obj : (ArrayList)object) {
Log.v("25",""+((ParseObject) obj).get("title"));
}
}
});
我的Cloud Code方法:
Parse.Cloud.define ('getFoo', function (req, res) {
var arrayIngredients = [];
arrayIngredients = req.params.ingredients;
var recepyQuery = new Parse.Query("Foos");
recepyQuery.find( {
success: function(result) {
res.success(result);
},
error: function() {
res.error("Nothing here");
}
});
});
此代码完美无缺,但如果我取消注释par.put(...)部分,则会出现此错误:
com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
这是我的错误堆栈:
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Looper.loop(Looper.java:146)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5653)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at dalvik.system.NativeStart.main(Native Method)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: Caused by: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:136)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:97)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCommand.<init>(ParseRESTCommand.java:138)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.<init>(ParseRESTCloudCommand.java:22)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.callFunctionCommand(ParseRESTCloudCommand.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloudCodeController.callFunctionInBackground(ParseCloudCodeController.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud$1.then(ParseCloud.java:64)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud$1.then(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:726)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$13.then(Task.java:818)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$13.then(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:690)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:796)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:830)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:99)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.starter.MainActivity.onCreate(MainActivity.java:62)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Activity.performCreate(Activity.java:5541)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.access$900(ActivityThread.java:172)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: ... 7 more
这是我犯的错误还是Parse存在问题? 我正在使用Parse Server和Parse的Android SDK 1.13.0
答案 0 :(得分:1)
不要在值中传递String[]
,只需传递String
,为此您应该更改您的请求代码,如下所示 -
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", "someIngredientValue"});
ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
//the rest of your code ...
在接收端,你说request.params.ingredients
- 这应该给你'someIngredientValue'。
我希望这会有所帮助。