gpt4 book ai didi

android - 使用android在Parse中插入多个数据

转载 作者:行者123 更新时间:2023-11-29 14:14:04 25 4
gpt4 key购买 nike

我有一个应用程序可以从解析中插入和检索数据。但我需要在一个 ID 下的单个任务中插入多个条目。我可以使用循环来做到这一点,但是无论如何可以一次插入多个条目吗?例如:我有一个用户 ID“ABC”,这个用户输入了一些数据,例如:data-1(abc, Ny, water), data-2(xyz,bristol, air), data-3( qwe, ca,火)。我怎样才能将 ABC id 下的所有 3 个数据一起插入到解析中?

ParseObject userOrder = new ParseObject("tableName");
userOrder.put("userId", userId);
userOrder.put("data",data);
userOrder.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null){
//successfully data inserted
}
else {
//there is an error in data insertion }
}
});

最佳答案

是的,你可以使用 saveAllinBackground 来做到这一点

final List<ParseObject> parseTaskObjects = new ArrayList<>();
for (TaskResponse taskResponse : ((MainApplication)(getApplicationContext())).getTaskResponses()) {
ParseObject parse_assignment = new ParseObject("TaskResponse");
parse_assignment.put("TaskID", list.get(((MainApplication) (getApplicationContext())).getTaskResponses().indexOf(taskResponse)));
parse_assignment.put("AssignmentId", assignment);
if (taskResponse.getTaskType() == TaskType.LOCATION.ordinal()) {
parse_assignment.put("LocationResp", getParseGeoPointFromLatLng(taskResponse.getLocationResponse().latitude, taskResponse.getLocationResponse().longitude));
} else if (taskResponse.getTaskType() == TaskType.PICTURE.ordinal()) {
ParseFile file = new ParseFile("image.jpg", taskResponse.getPictureResponse());
file.saveInBackground();
parse_assignment.put("PicResp", file);
} else if (taskResponse.getTaskType() == TaskType.TAGS.ordinal()) {
parse_assignment.put("TagResp", taskResponse.getTagResponse());
} else if (taskResponse.getTaskType() == TaskType.TEXT.ordinal()) {
parse_assignment.put("TextResp", taskResponse.getTextResponse());
} else if (taskResponse.getTaskType() == TaskType.NUMBER.ordinal()) {
parse_assignment.put("NumResp", taskResponse.getNumberResponse());
}

parseTaskObjects.add(parse_assignment);
}

ParseObject.saveAllInBackground(parseTaskObjects, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(Stint_task.this, "Stint Tasks Completed Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Stint_task.this, "Stint Failed", Toast.LENGTH_SHORT).show();
}
}
});

关于android - 使用android在Parse中插入多个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32580450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com