jquery - why file json isn't read by the program? -


hi don't understand why if write in variable json right:

var theui  = { "nodes":{"progetto 1":{"color":"red", "shape":"dot", "alpha":1}, "demos":{"color":"#b2b19d", shape:"dot", "alpha":1}, "halfviz":{"color":"#a7af00", "alpha":0, "link":""}, "atlas":{"color":"#a7af00", "alpha":0, "link":""}, "echolalia":{"color":"#a7af00", "alpha":0, "link":""}, "docs":{"color":"#b2b19d", "shape":"dot", "alpha":1}, "reference":{"color":"#922e00", "alpha":0, "link":""}, "introduction":{"color":"#922e00", "alpha":0, "link":""}, "code":{"color":"#b2b19d", "shape":"dot", "alpha":1}, "github":{"color":"orange", "alpha":0, "link":""}, ".zip":{"color":"orange", "alpha":0, "link":""}, ".tar.gz":{"color":"orange", "alpha":0, "link":""} }, "edges":{ "progetto 1":{ "demos":{"length":.8}, "docs":{"length":.8}, "code":{"length":.8} }, "demos":{"halfviz":{}, "atlas":{}, "echolalia":{} }, "docs":{"reference":{}, "introduction":{} }, "code":{".zip":{}, ".tar.gz":{}, "github":{} } } } var sys = arbor.particlesystem() sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015}) sys.renderer = renderer("#sitemap") sys.graft(theui) var nav = nav("#nav") $(sys.renderer).bind('navigate', nav.navigate) $(nav).bind('mode', sys.renderer.switchmode) nav.init() }) 

while if give data file json, program doesn't work:

var theui  = $.getjson("data.json")   var sys = arbor.particlesystem() sys.parameters({stiffness:900, repulsion:2000, gravity:true, dt:0.015}) sys.renderer = renderer("#sitemap") sys.graft(theui) var nav = nav("#nav") $(sys.renderer).bind('navigate', nav.navigate) $(nav).bind('mode', sys.renderer.switchmode) nav.init() }) 

it , read json program doesn't work.

the file data.json this:

{ "nodes":{"progetto 1":{"color":"red", "shape":"dot", "alpha":1}, "demos":{"color":"#b2b19d", shape:"dot", "alpha":1}, "halfviz":{"color":"#a7af00", "alpha":0, "link":""}, "atlas":{"color":"#a7af00", "alpha":0, "link":""}, "echolalia":{"color":"#a7af00", "alpha":0, "link":""}, "docs":{"color":"#b2b19d", "shape":"dot", "alpha":1}, "reference":{"color":"#922e00", "alpha":0, "link":""}, "introduction":{"color":"#922e00", "alpha":0, "link":""}, "code":{"color":"#b2b19d", "shape":"dot", "alpha":1}, "github":{"color":"orange", "alpha":0, "link":""}, ".zip":{"color":"orange", "alpha":0, "link":""}, ".tar.gz":{"color":"orange", "alpha":0, "link":""} }, "edges":{ "progetto 1":{ "demos":{"length":.8}, "docs":{"length":.8}, "code":{"length":.8} }, "demos":{"halfviz":{}, "atlas":{}, "echolalia":{} }, "docs":{"reference":{}, "introduction":{} }, "code":{".zip":{}, ".tar.gz":{}, "github":{} } } } 

you need use callback function -

$.getjson("data.json", function (theui) {     var sys = arbor.particlesystem();     sys.parameters({         stiffness: 900,         repulsion: 2000,         gravity: true,         dt: 0.015     });     sys.renderer = renderer("#sitemap");     sys.graft(theui);     var nav = nav("#nav");     $(sys.renderer).bind('navigate', nav.navigate);     $(nav).bind('mode', sys.renderer.switchmode);     nav.init(); }); 

also,

jsonlint test : http://jsonlint.com/

parse error on line 9: ...2b19d",            shape: "dot",       ----------------------^ expecting 'string' 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -