It is unfortunate that the JSON parser can't tell in more detail what is wrong with the text it is parsing, but I expect the problems are the following:
* All property names must be quoted with double quotes. * All strings must use double quotes. * new Date() is not allowed, since it is a JS expression. JSON doesn't support date or time values, so we allow you to used a string format that is the same as the Date constructor, without 'new'. So use "Date(2015, 11, 31)" for December 31, 2015. Note that month indexes are 0-based, so 11 is December. That's standard across most programming languages. On Sat, Jan 23, 2016 at 1:15 PM, Gianluca Albanese <[email protected]> wrote: > hi Daniel, > thanks for your answer with which I was able to fix the error. > For now I have another problem to solve. > I tried to upload the data via ajax to generate the graph, but I get the > following error > > ERROR > Uncaught Error: Invalid JSON string: { > cols:[{id:'Fase',label:'Fase',type:'string'},{id:'Responsabile',label:'Responsabile',type:'string'},{id:'Inizio',label:'Inizio',type:'date'},{id:'Fine',label:'Fine',type:'date'}], > rows:[{c:[{v:'1'},{v:'Philip'},{v: new Date(2015,01,01)},{v: new > Date(2015,12,31)}]},{c:[{v:'2'},{v:'George'},{v: new Date(2016,01,01))},{v: > new Date(2016,12,31)}]},{c:[{v:'3'},{v:'Anthony'},{v: new > Date(2017,01,01))},{v: new Date(2017,12,31)}]}]} > > this my code > <html> > <head> > <script type="text/javascript" src="loader.js"></script> > <script type="text/javascript" src="jquery-1.12.0.min.js"></script> > <script type="text/javascript"> > var result = $.ajax("http://localhost/gantt_json.asp", { > async: false, > data: {fk_obbiettivo: '25'}, > }).responseText; > console.log(result); > > > google.charts.load('current', { > 'packages': ['timeline'] > }); > google.charts.setOnLoadCallback(drawChart); > > function drawChart() { > var container = document.getElementById('timeline'); > var chart = new google.visualization.Timeline(container); > var dataTable = new google.visualization.DataTable(result); > > chart.draw(dataTable); > } > </script> > </head> > <body> > <div id="timeline" style="height:300px;"></div> > </body> > </html> > > I think the error is due to the string generated from the page > gantt_json.asp but I can not figure out where I'm wrong. > This is the code of the page gantt_json.asp > > > <% > Response.ContentType = "application/json" > 'colonne > Response.Write("{ cols:[") > Response.Write("{id:'Fase',label:'Fase',type:'string'},") > Response.Write("{id:'Responsabile',label:'Responsabile',type:'string'},") > Response.Write("{id:'Inizio',label:'Inizio',type:'date'},") > Response.Write("{id:'Fine',label:'Fine',type:'date'}],") > 'righe > Response.Write(" rows:[") > Response.Write("{c:[{v:'1'},{v:'Philip'},{v: new Date(2015,01,01)},{v: new > Date(2015,12,31)}]},") > Response.Write("{c:[{v:'2'},{v:'George'},{v: new Date(2016,01,01))},{v: > new Date(2016,12,31)}]},") > Response.Write("{c:[{v:'3'},{v:'Anthony'},{v: new Date(2017,01,01))},{v: > new Date(2017,12,31)}]}") > Response.Write("]}") > %> > > I hope you can help me again and I thank you in advance. > Gianluca > > -- > You received this message because you are subscribed to the Google Groups > "Google Visualization API" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to > [email protected]. > Visit this group at > https://groups.google.com/group/google-visualization-api. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-visualization-api/bc22a8cc-c87b-4ab4-aa72-3897d9f9763d%40googlegroups.com > <https://groups.google.com/d/msgid/google-visualization-api/bc22a8cc-c87b-4ab4-aa72-3897d9f9763d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> [email protected] <[email protected]> 5CC, Cambridge MA -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-visualization-api. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJMwHhT_VGMjR0a00UgaK_OwyFa0ZXwyPX8jDN7bhHB__g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
