获取双嵌套 JSON 响应解析 Javascript API
Posted
技术标签:
【中文标题】获取双嵌套 JSON 响应解析 Javascript API【英文标题】:Get Double Nested JSON Response Parse Javascript API 【发布时间】:2017-12-02 21:03:58 【问题描述】:我正在调用我的 Parse 服务器并使用 Parse javascript API 将数据拉入我的 Angular V1(是 JS 还是 IO?!)应用程序。我的调用函数如下:
$scope.getInventoryItems = function ()
var query = new Parse.Query("Inventory");
query.include("product");
query.include("retailer");
query.find(
success: function (results)
$scope.inventoryItems = [];
for (i = 0; i < results.length; i++)
var p = results[i].get("product");
var r = results[i].get("retailer");
var inventoryItem =
objectId: results[i].id,
productObjectId: p.id,
barcode: p.get("barcode"),
productName: p.get("name"),
imageUrl: p.get("image"),
Qty: results[i].get("QTY"),
newQty: results[i].get("QTY"),
shoppingQty: 1,
retailerImage: r.get.Logo("url"),
retailerName: r.get("Name")
console.log(inventoryItem);
$scope.inventoryItems[$scope.inventoryItems.length] = inventoryItem;
$scope.$apply();
,
error: function (error)
console.log("Query Error: " + error.message);
)
这是 JSON 服务器响应:
"results": [
"objectId": "Fo02snRmlP",
"product":
"objectId": "eCA7BwB7kF",
"barcode": 54775912,
"name": "Extra Peppermint Gum 5 Pack",
"image": "[image url removed]",
"createdAt": "2017-11-22T01:28:16.605Z",
"updatedAt": "2017-11-22T01:28:16.605Z",
"__type": "Object",
"className": "Products"
,
"QTY": 4,
"createdAt": "2017-11-22T01:28:16.859Z",
"updatedAt": "2017-11-22T01:28:16.859Z",
"ACL":
"NV6ubzeAHL":
"read": true,
"write": true
"retailer":
"objectId": "u2qNoKDAWV",
"Name": "My Supermarket",
"createdAt": "2017-09-20T17:16:48.151Z",
"updatedAt": "2017-11-13T19:40:26.371Z",
"Logo":
"__type": "File",
"name": "c600325c63f7fb252b36c08c8c6168ab_supermarket_logo_full.svg",
"url": "https://my-api.herokuapp.com//files/my-api/c600325c63f7fb252b36c08c8c6168ab_supermarket_logo_full.svg"
,
"shortName": "supermarket",
"__type": "Object",
"className": "Retailers"
,
,
一切都成功了,除了我尝试使用retailerImage: r.get.Logo("url")
收集的徽标 URL。我如何获得这个双嵌套项?
谢谢
【问题讨论】:
r.get:ACL.Logo('url') 【参考方案1】:Logo
是retailer
的另一个属性,对吧?看起来你只需要使用r.get('Logo').url()
这是parse docs example:
var profilePhoto = profile.get("photoFile");
$("profileImg")[0].src = profilePhoto.url();
【讨论】:
就是这样。谢谢! 很高兴为您提供帮助! :D以上是关于获取双嵌套 JSON 响应解析 Javascript API的主要内容,如果未能解决你的问题,请参考以下文章