ParseObject 的类型无效

Invalid type for ParseObject

错误: java.lang.IllegalArgumentException:ParseObject 的类型无效:class org.json.JSONObject

我已经将 "centOS" 上的解析服务器和数据库从 parse.com 移动到 mangoDB。当我从我的 android 应用发出以下请求时出现以上错误。

注意 : 我正在使用 android parse sdk(v1.13.1)

我尝试使用 addAllUnique() 方法将 jsonObject 添加为数组列表,因为我必须将 jsonObject 作为数据类型“array”存储在解析数据库中。

下面我分享我的代码:

JSONObject jsonObj = new JSONObject();

try {

    jsonObj.put("__type", "Pointer");
    jsonObj.put("className", className);
    jsonObj.put("objectId", objectId);
} catch (JSONException e1) {
    e1.printStackTrace();
}

ParseUser user = ParseUser.getCurrentUser();

user.addAllUnique("Keyword",Arrays.asList(jsonObj));

user.saveInBackground();

我也试过 user.addAll() 方法而不是 addAllUnique() 但它也不起作用。

请帮我解决这个问题。谢谢

你可以试试这样的东西而不是 JSON 对象。

List<ParseObject> pointerList = new ArrayList<>();
pointerList.add(ParseObject.createWithoutData("YourClassName", "yourobjectId"));
pointerList.add(ParseObject.createWithoutData("YourClassName", "yourobjectId"));
...
user.addAllUnique("keyWord", pointerList);
user.saveInBackground();

尚未测试代码。但从技术上讲,它应该有效。

希望对您有所帮助:)