json 应为开始_ARRAY,但在第1行第167列路径$.progress处为数字

hmae6n7t  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(99)

我已经阅读了几个关于这个问题的答案。我知道在我的自定义对象(AssignmentData)中,它需要数组,但实际上它也是一个名为progress的firestore数组。以下是firestore文档

assignmentId
       "irfan 1671299952415"
endTime
        "1671991147130"
exStatus
        0
game_nameId
        2
groupName
       "Math 101"
levelId
        "1"
number_of_exercises
        10

progress
        []

章节ID“1”

我的自定义对象

public class Assignmentsdata implements Serializable {

@SerializedName("exStatus")
@Expose
private Integer exStatus;
@SerializedName("groupName")
@Expose
private String groupName;
@SerializedName("teacherId")
@Expose
private String teacherId;
@SerializedName("game_nameId")
@Expose
private Integer gameNameId;
@SerializedName("levelId")
@Expose
private String levelId;
@SerializedName("students")
@Expose
private List<PersonModel> students = null;
@SerializedName("progress")
@Expose
private ArrayList<String> progress = null;

public Integer getExStatus() {
    return exStatus;
}

public void setExStatus(Integer exStatus) {
    this.exStatus = exStatus;
}

public String getGroupName() {
    return groupName;
}

public void setGroupName(String groupName) {
    this.groupName = groupName;
}

public String getTeacherId() {
    return teacherId;
}

public void setTeacherId(String teacherId) {
    this.teacherId = teacherId;
}

public Integer getGame_nameId() {
    return gameNameId;
}

public void setGameNameId(Integer gameNameId) {
    this.gameNameId = gameNameId;
}


public ArrayList<String> getProgress() {
    return progress;
}

public void setProgress(ArrayList<String> progress) {
    this.progress = progress;
}
  • 有一个数组,我期待一个数组,那么是什么导致了错误?*
DocumentSnapshot document = task.getResult();
                            try {
                                Gson gson = new Gson();
                                String json = gson.toJson(document.getData());

     // tried map directly from document but outcome is same.
    //Assignmentsdata assignmentsdata = document.toObject(Assignmentsdata.class);
                                Assignmentsdata assignmentsdata = gson.fromJson(json, Assignmentsdata.class);

                                if (assignmentsdata != null) {
                                    filtered_invitation_list.add(assignmentsdata);
                                }
                            }catch (NullPointerException e){
                               Log.d("Failure", "No exception here: ", 
                            }

                            if (finalI == teachers.size() - 1) {
                                try {

错误显示在异常下方,而不是实际获取对象的位置上方。

consumer.accept(filtered_invitation_list);
                                } catch (Exception e) {
                                    Log.d("Failure", "Here is get the exception: ", e);
                                }

                            }
eulz3vhy

eulz3vhy1#

我在此代码处收到上述错误。

consumer.accept(filtered_invitation_list);
                            } catch (Exception e) {
                                Log.d("Failure", "Here is get the exception: ", e);
                            }
                        }

但是Map来自firestore的对象没有问题,问题是ViewModel和观察来自firestore的对象列表。我已经在本地保存了一些赋值,因为对象结构或字段不匹配,它在我的Fragment类中给出了一个错误,但是在我的存储库中观察到了这个错误。我知道为什么错误会回到存储库中有点棘手。

viewModel.getActiveAssignments.observe(getViewLifecycleOwner(), this::getAssignmentsData);
private void getAssignmentsData(ArrayList<Assignmentsdata> assignmentsdata) {
    // get the data saved locally and merge with new incoming.

相关问题