解析JavaScript中的抓取响应

时间:2018-08-12 17:34:49

标签: javascript json fetch

我一定很累,但是我无法弄清楚。我有以下代码:

            fetch(url, options)
            .then(function(response) {
                return response.json();
            })
            .then(function(myJson) {
                setTimeout(function(){ 
                if (myJson == undefined) 
                {
                    console.log("fetch failed")
                } 
                else 
                {
                    //inspect the data that the WebAPI returned
                    console.log("myJson: ", myJson);
                }
                }, 3000);
            });

变量url填充有一个API url,该API url返回以下数据字符串(我通过输入用于直接提取到浏览器中的字符串来获得此数据):

  

{“产品”:[{“条形码编号”:“ 5000159459228”,“条形码类型”:“ EAN”,“条形码格式”:“ EAN 5000159459228”,“ mpn”:“”,“型号”:“”,“ asin“:” B01K4FU9K6“,” product_name“:” Twix(50g x 6)“,” title“:”“,” category“:”玩具与游戏>玩具>假装游戏>假装购物与杂货“,”制造商“ :“火星”,“品牌”:“”,“标签”:“火星”,“作者”:“”,“出版商”:“火星”,“艺术家”:“”,“演员”:“”,“导演“:”“,”工作室“:”“,”流派“:”“,” auditing_rating“:”“,”成分“:”“,” nutrition_facts“:”“,” color“:”“,”格式“:”“,” package_quantity“:”“,” size“:”“,” length“:”“,” width“:”“,” height“:”“,” weight“:”“,” release_date“ :“”,“描述”:“牛奶巧克力覆盖的焦糖和饼干。”,“功能”:[],“图像”:[“ https://images.barcodelookup.com/4488/44880860-1.jpg”],“商店”:[{“ store_name”:“ Rakuten Deutschland GmbH“,” store_price“:” 23.57“,” product_url“:” https://www.rakuten.de/produkt/twix-32-riegel-grosspack-2179063860“,” currency_code“:” EUR“,” currency_symbol“:”€“}],”评论“:[]} ]}

当我在控制台上查看日志时,这就是我看到的:

enter image description here

由于某种原因,我无法弄清楚如何引用myJson对象中的特定元素。

我如何引用条形码格式字段?

谢谢。

0 个答案:

没有答案
相关问题