gpt4 book ai didi

json - 如何在 Parse 中从 JSON 创建特定类型的对象

转载 作者:行者123 更新时间:2023-12-05 00:24:19 26 4
gpt4 key购买 nike

我有一个从服务中提取一些 JSON 的 Cloud Code 脚本。该 JSON 包含一个对象数组。我想将它们保存到 Parse,但使用特定的 Parse 类。我该怎么做?

这是我的代码。

Parse.Cloud.httpRequest({
url: 'http://myservicehost.com',
headers: {
'Authorization': 'XXX'
},
success: function(httpResponse) {
console.log("Success!");

var json = JSON.parse(httpResponse.text);
var recipes = json.results;

for(int i=0; i<recipes.length; i++) {
var Recipe = Parse.Object.extend("Recipe");
var recipeFromJSON = recipes[i];
// how do i save recipeFromJSON into Recipe without setting all the fields one by one?
}
}
});

最佳答案

我想我得到了它的工作。您需要将 JSON 数据对象中的 className 属性设置为您的类名。 (在 source code 中找到它)但我只在客户端尝试过这个。

for(int i=0; i<recipes.length; i++) {
var recipeFromJSON = recipes[i];
recipeFromJSON.className = "Recipe";
var recipeParseObject = Parse.Object.fromJSON(recipeFromJSON);
// do stuff with recipeParseObject
}

关于json - 如何在 Parse 中从 JSON 创建特定类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26473226/

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