java - 多个 JSONObject 键和值不会保存到 Parse

标签 java android json parse-platform

I have an adapter class with a checkbox and when the checkbox is selected it pushes a JSONObject key and value to Parse.在我的应用程序中,它仅将一个键和值作为 JSONObject 保存到 Parse,我希望我的应用程序在选择其他复选框时将多个键和值保存到 Parse。

当我选择不同的复选框时,它会更改单个键和值,而不是将另一组添加到 JSONObject

Photo of the row inside Parse including the JSONObject

相反
{"2c1":true, "2c2":true, "2c3":true, "2c4":true, "2c5":true, "2c6":true}

与其单独拥有这个

{"2c1":true}

这是我的 Adapter 类中的代码

ChecklistAdapter.java

   final JSONObject myObject = new JSONObject();
    try {
        myObject.put(dataRecord.getID(), true);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    checkBox.setOnClickListener(new View.OnClickListener() {

        String idSelected = dataRecord.getID();

        public void onClick(View v) {


            if (((CheckBox) v).isChecked()) {

                ParseUser.getCurrentUser().put("checklistData", myObject);
                ParseUser.getCurrentUser().saveInBackground();

                Toast.makeText(getContext(), idSelected,
                        Toast.LENGTH_SHORT).show();

            } else {

                Toast.makeText(getContext(), "CheckBox is unchecked",
                        Toast.LENGTH_SHORT).show();

            }
        }
    });

提供的功能代码只是保存键值对。

编辑:如果您对单击此处的复选框时 Toast 的作用感到好奇。

enter image description here

最佳答案

final JSONObject myObject = new JSONObject();

checkBox.setOnClickListener(new View.OnClickListener() {

    String idSelected = dataRecord.getID();

    public void onClick(View v) {


        if (((CheckBox) v).isChecked()) {

        try {
              myObject.put(dataRecord.getID(), true);
        } catch (JSONException e) {
              e.printStackTrace();
        }


            ParseUser parseUser= ParseUser.getCurrentUser();
            parseUser.put("checklistData", myObject);
            parseUser.saveInBackground();

            Toast.makeText(getContext(), idSelected,
                    Toast.LENGTH_SHORT).show();

        } else {

            Toast.makeText(getContext(), "CheckBox is unchecked",
                    Toast.LENGTH_SHORT).show();

        }
    }
});

关于java - 多个 JSONObject 键和值不会保存到 Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258972/

相关文章:

java - 如何在 Java 中将文件输入分段

java - 处理餐厅场景中的同时预订请求

java - 使用实现而不是编译时无法访问库模块依赖项

javascript - 所有键的键码值均返回为 229

Java文档

java - JPA 连接到错误的表

android - 使用 RecyclerView 跨越多个列

ios - 如何将 apple-app-site-association 的 content/mime 类型设置为 application/json

json - 是否可以在没有模板消息的情况下使用 NLog 的结构化日志记录?

ios - 预期方法调用的参数太多 1 有 3