0

I have an array that looks like this (using var_dump in php):

string '[{"US":"2"},{"England":"0"},{"Mexico":"0"},{"France":"0"},{"Canada":"0"},{"Spain":"0"},{"Italy":"0"},{"Australia":"0"},{"Japan":"0"},{"China":"0"},{"Korea":"0"}]' 

I need to extract both columns in javascript but I obviously fail whatever I tried

This is what I tried so far:

var dbdata = <?php echo json_encode($dataset1); ?>;

 for (var key in dbdata) {
        for (var key2 in dbdata[key]) {
            alert("Country " + key2 + " No of member is " + key);
        }
    }

I get the country right, but the key is the index not the column value. How should be be fixed?

Thanks

4

1 回答 1

0
dbdata[key][key2]

包含号码。

http://jsfiddle.net/NPTQB/

var data = [{"US":"2"},{"England":"0"},{"Mexico":"0"},{"France":"0"},{"Canada":"0"},{"Spain":"0"},{"Italy":"0"},{"Australia":"0"},{"Japan":"0"},{"China":"0"},{"Korea":"0"}];

for (var key in data) {
     for (var key2 in data[key]) {
         alert("Country " + key2 + " No of member is " + data[key][key2]);
     }
}
于 2013-09-09T12:48:44.850 回答