简体   繁体   English

从json数组获取值

[英]get values from json array

i trying to get the sku from a url www.mbsmfg.co/shop/coles-grey/?format=json-pretty (json) and show the users those values which are available under the variants for that particular product 我试图从网址www.mbsmfg.co/shop/coles-grey/?format=json-pretty(json )获取sku ,并向用户显示在该特定产品的变体下可用的值

eg: when a user visits this page www.mbsmfg.co/shop/coles-grey/ the user must be able to see the SKU in the product body. 例如:当用户访问该页面www.mbsmfg.co/shop/coles-grey/时 ,用户必须能够在产品正文中看到SKU。

Im using YUI for this and so far 我到目前为止一直在使用YUI

function ajaxRequest() {
     Y.io('//www.mbsmfg.co/shop/coles-grey/?format=json-pretty', {
         on: {
             success: function (x, o) {
                 var parsedResponse;
                 try {
                     d = Y.JSON.parse(o.responseText);
                 } catch (e) {
                     console.log("JSON Parse failed!");
                     return;
                 }

                 for (var i = 0; i < d.items.length; i++) {
                     var htmlString = '<h1>' + d.items[i].sku + d.items[i].price '</h1>' + d.items[i].body;
                     Y.one('.product-sharing').append(htmlString);
                    alert(htmlString);
                 }

             }
         }
     });
 }

Y.use('node', function() {
     Y.on('domready', function() {
         ajaxRequest();
     });
 });

It doesn't alert or append the values to the div. 它不会警告或将值附加到div。

Can someone please tell me what am i doing wrong here? 有人可以告诉我我在做什么错吗?

I think you are looking into the wrong place. 我认为您正在寻找错误的地方。 This should give you the sku value. 这应该为您提供sku值。

d.item.structuredContent.variants[0].sku

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM