【问题标题】:Uncaught SystaxError while sending JSONArray converted to String as parameter in Parse Cloud Function发送转换为字符串的 JSONArray 作为 Parse Cloud Function 中的参数时未捕获的 SystaxError
【发布时间】:2025-12-24 03:00:11
【问题描述】:

TL:DR;如何在 Parse Cloud Functions 中发送 JSONArray 作为参数?

我正在请求 Parse Cloud 函数。每当我尝试将 JSONArray 转换为 String 并作为参数发送时,我都会收到此异常

Uncaught SyntaxError: Unexpected token u in <unknown file>:1

以下是我的代码,这与 Parse Guide 中的示例代码相同:

// create a JSONObject
JSONObject singleJsonObj= new JSONObject();
singleJsonObj.put("time", "2017-01-01T06:00:00Z");
singleJsonObj.put("title", "Adib");
singleJsonObj.put("profile", "AbCdIj76");

// add JSONObject to JSONArray
JSONArray jsonArray = new JSONArray();
jsonArray.put(singleJsonObj);

// put as parameter
HashMap<String, Object> params = new HashMap<>();
params.put("form", formId);
params.put("records", jsonArray.toString());

ParseCloud.callFunctionInBackground("someFunctionName", params, new FunctionCallback<Float>() {
    @Override
    public void done(Float object, ParseException e) {
        if (e == null) {
            // Yay!
        } else {
            // Damn!!
        }
    }
});

如果我不将它作为字符串发送,它会显示另一个错误为 InvalidArgumentException: Invalid type for ParseObject: JSONArray。我还没有找到任何关于如何在 Parse Cloud Function 中发送 JSONArray 作为参数的官方文档。

【问题讨论】:

    标签: parse-platform parse-cloud-code


    【解决方案1】:

    callFunctionInBackground 有多个重载版本。如果它是一个云功能,你应该使用这个:https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParseCloud.java#L17

    并将回调定义为:new FunctionCallback()

    希望对你有帮助。

    【讨论】: