Mac*_*tle 4 json parse-platform parse-cloud-code
我有一个Cloud Code脚本,可以从服务中提取一些JSON.该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?
}
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
我想我搞定了.您需要将JSON数据对象中的className属性设置为您的类名.(在源代码中找到它)但我只在客户端尝试过这个.
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1294 次 |
| 最近记录: |