weixin_33736649 2018-07-05 15:06 采纳率: 0%
浏览 106

Chrome扩展程序json文件

I'm using Chrome Extension to change a sites CSS/javascript.

I'm looking to manipulate the layout and get data.

Inspecting the code on the website I can see it has a json file, similar to the below:

< form id='preference' data-json={'name':'test','age':'40'},{'name':'test','age':'30'},{'name':'test','age':'50'} >

How would I loop through the information in the JSON file?

  • 写回答

1条回答 默认 最新

  • weixin_33721427 2018-07-05 15:36
    关注

    Suppose you have a JSON like this or you convert your data like the format below:

    var data =   [{
            "name": "test",
            "age": "40"
        }, {
            "name": "test",
            "age": "30"
        }, {
            "name": "test",
            "age": "20"
        }]
    

    As you are asking, how to loop through JSON. Follow this:

    data.forEach(function(d){
                    console.log("Name: " + d.name);
                    console.log("Age: " + d.age);
                });
    
    评论

报告相同问题?