I have a Javascript code that uses an array of objects as:
var words = [{"text":"This", "url":"http://google.com/"},
{"text":"is", "url":"http://bing.com/"},
{"text":"some", "url":"http://somewhere.com/"},
{"text":"random", "url":"http://random.org/"},
{"text":"text", "url":"http://text.com/"},
{"text":"InCoMobi", "url":"http://incomobi.com/"},
{"text":"Yahoo", "url":"http://yahoo.com/"}]
Then I use words
in the rest of code and everything works fine.
Then I store the data in a JSON file, lets call the file "myfile.json" its content is:
{
"words": [
{"text":"This", "url":"http://google.com/"},
{"text":"is", "url":"http://bing.com/"},
{"text":"random", "url":"http://random.org/"},
{"text":"some", "url":"http://somewhere.com/"},
{"text":"text", "url":"http://text.com/"},
{"text":"InCoMobi", "url":"http://incomobi.com/"},
{"text":"Yahoo", "url":"http://yahoo.com/"}
]
}
I load this file using d3.json
as:
d3.json("myfile.json", function(words) {
console.log(words); //Log output to console
});
And then I use words
the same as before, now my code does not work!
What is the difference between the two things and how can I fix the second method that I load the file?
{ "words": [ ...
I had{"X": [...
then what would I use? – TJ1 Apr 20 at 15:17