Parse platform Can';不创建解析对象
这是我创建的一个后台工作,用于从Google工作表获取JSON,解析它,创建解析对象,然后将它们保存到我的解析核心Parse platform Can';不创建解析对象,parse-platform,Parse Platform,这是我创建的一个后台工作,用于从Google工作表获取JSON,解析它,创建解析对象,然后将它们保存到我的解析核心 Parse.Cloud.job("importPlaylists", function(request, status) { // Use master key Parse.Cloud.useMasterKey(); // ID of the Google Spreadsheet var spreadsheetID = "someId";
Parse.Cloud.job("importPlaylists", function(request, status) {
// Use master key
Parse.Cloud.useMasterKey();
// ID of the Google Spreadsheet
var spreadsheetID = "someId";
var sheetID = "anotherId";
var url = "https://spreadsheets.google.com/feeds/list/" + spreadsheetID + "/" + sheetID + "/public/values?alt=json";
// Cloud function
Parse.Cloud.httpRequest({
url: url
}).then(function(httpResponse) {
// Parse response
var json = JSON.parse(httpResponse.buffer);
// Array to store new objects
var playlistsToSave = [];
// Create playlist objects
for (var i = 0; i < json.feed.entry.length; i++) {
var each = json.feed.entry[i];
var name = each["gsx$name"]["$t"];
var playlistid = each["gsx$playlistid"]["$t"];
var description = each["gsx$description"]["$t"];
var imageurl = each["gsx$imageurl"]["$t"];
var categories = each["gsx$categories"]["$t"].split(',');
// -- Logs
console.log('name = ' + name);
console.log('playlistid = ' + playlistid);
console.log('description = ' + description);
console.log('imageurl = ' + imageurl);
// Create Parse objects
var Playlist = Parse.Object.extend("Playlist");
var playlist = new Playlist();
playlist.set("name", name);
playlist.set("playlistid", playlistid);
playlist.set("description", description);
playlist.set("imageurl", imageurl);
playlist.set("categories", categories);
// -- Logs
console.log(playlist.playlistid);
// Add to caching array
playlistsToSave.push(playlist);
}
console.log('playlistsToSave = ');
console.log(playlistsToSave);
// Parse - Save objects
Parse.Object.saveAll(playlistsToSave, {
success: function(saveList) {
status.success("Objects created successfully.");
},
error: function(error) {
status.error("Unable to save objects.");
}
});
},function(httpResponse) {
// error
console.error('Request failed with response code ' + httpResponse.status);
status.error("Scheduled messages error: " + error);
});
});
返回:
I2015-06-11T06:11:21.235Z]No Message provided
此外,日志记录:
console.log('playlistsToSave = ');
console.log(playlistsToSave);
返回:
I2015-06-11T06:11:21.236Z]playlistsToSave =
我根据Luca的回答将日志更改为:
console.log(playlist.get("playlistid"));
它会打印出一个值,从而创建播放列表对象并设置值。而且:
console.log(playlistsToSave.length);
显示值2
有趣的是,我在执行此操作时收到了一条成功消息,并保存了要解析的播放列表对象
显然,这一行:
console.log(playlistsToSave);
导致云日志中的消息出错:
Failed with: Uncaught Tried to save an object with a pointer to a new, unsaved object.
为什么??我不知道。因此,我的调试日志记录从一开始就错了,让我放弃了,但尝试注销该阵列也导致了异常。我来自objective-c背景,因此注销这样的数组将打印数组对象 为了检查playlist对象属性是否保留值,因为它是一个解析对象,您应该这样做:
console.log(playlist.get(“playlistid”)代码>
Failed with: Uncaught Tried to save an object with a pointer to a new, unsaved object.