Weird Failure - invalid JSON string but JSON is valid

455 views
Skip to first unread message

Manuel

unread,
May 8, 2015, 4:07:16 AM5/8/15
to google-visua...@googlegroups.com
Hi all,

I just encountered a weird problem.I get the following error:

Uncaught Error: Invalid JSON string: 


<!DOCTYPE html>



<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-de" 

AND A LOT MORE THEREAFTER

when I use this code:

<html>
  <head>
  
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="varChart.js" type="text/javascript"></script> 
  <script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart', 'bar']});
google.setOnLoadCallback(drawBasic);

function drawBasic() {

      var jsonData = jQuery.ajax({
url: "charting/Country.php?country=2&Type=0",
dataType:"json",
async: false
}).responseText
var data = new google.visualization.DataTable(jsonData);

      var options = {
      };

      var chart = new google.visualization.ColumnChart(
        document.getElementById('chart_div'));

      chart.draw(data, options);
    }
</script> 
  
  </head>
  <body>

  <div id="chart_div" style="height: 300px;margin-top:10px"></div>
  <p style="font-size: x-small;color: grey;text-align: right;">Quelle: eigene Berechnung, OECD Housing Prices database; OECD Economic Outlook database</p>
  
  
  </body>
</html>

But when I vaildate my JSON everything is just fine!

Can anybody help me on this? Do you need mor information?

Thank you very much

Best
Manu


Sergey Grabkovsky

unread,
May 8, 2015, 10:14:18 AM5/8/15
to google-visua...@googlegroups.com
Your code looks fine. Since your JSON is what's failing, please post an example of it. It's possible that your JSON is valid, but just not what the DataTable is expecting.

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Manuel

unread,
May 8, 2015, 1:02:39 PM5/8/15
to google-visua...@googlegroups.com
Sergey,

following my JSON:
{ "cols":[ {"id":"","label":"Land","type":"string"}, {"id":"","label":"Bewertung","type":"number"}, {"type":"string","role":"style"}], "rows": [{"c":[ {"v":"Neuseeland","f":null}, {"v":0.694,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Kanada","f":null}, {"v":0.6779,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Norwegen","f":null}, {"v":0.6533,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Australien","f":null}, {"v":0.6483,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Belgien","f":null}, {"v":0.5923,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Grossbritanien","f":null}, {"v":0.5427,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Schweden","f":null}, {"v":0.4668,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Frankreich","f":null}, {"v":0.3631,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Brasilien","f":null}, {"v":0.2624,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Irland","f":null}, {"v":0.2479,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Finnland","f":null}, {"v":0.2396,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Israel","f":null}, {"v":0.2105,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Dänemark","f":null}, {"v":0.2022,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Niederlande","f":null}, {"v":0.1762,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Spanien","f":null}, {"v":0.1728,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Österreich","f":null}, {"v":0.1577,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Türkei","f":null}, {"v":0.153,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Süd Afrika","f":null}, {"v":0.1274,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Luxemburg","f":null}, {"v":0.1106,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Mexiko","f":null}, {"v":0.0737,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Schweiz","f":null}, {"v":0.0587,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"USA","f":null}, {"v":0.0533,"f":null},{"v":"#0F2047","f":null}]},{"c":[ {"v":"Russland","f":null}, {"v":0.0128,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"China","f":null}, {"v":0.0104,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Italien","f":null}, {"v":0.0099,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Island","f":null}, {"v":-0.0252,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Tschechische Republik","f":null}, {"v":-0.0336,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Deutschland","f":null}, {"v":-0.0452,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Estland","f":null}, {"v":-0.0735,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Slowakei","f":null}, {"v":-0.0907,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Litauen","f":null}, {"v":-0.1032,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Lettland","f":null}, {"v":-0.1178,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Portugal","f":null}, {"v":-0.1207,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Korea","f":null}, {"v":-0.1477,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Indonesien","f":null}, {"v":-0.1529,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Slowenien","f":null}, {"v":-0.1538,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Ungarn","f":null}, {"v":-0.1594,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Griechenland","f":null}, {"v":-0.1931,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Japan","f":null}, {"v":-0.2535,"f":null},{"v":"#A9B6D4","f":null}]}]}

Best
Manuel
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

Sergey Grabkovsky

unread,
May 8, 2015, 1:31:31 PM5/8/15
to google-visua...@googlegroups.com
That's odd. I was able to use your data to render a column chart: http://jsfiddle.net/6kjs401c/

Is there any chance you could post a link to a failing page? If you're not comfortable posting a link on the forum, please feel free to email me at grabks <at> google.com

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.

--
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 google-visualizati...@googlegroups.com.

Manuel

unread,
May 8, 2015, 2:19:34 PM5/8/15
to google-visua...@googlegroups.com
Just snet you an Email


Am Freitag, 8. Mai 2015 19:31:31 UTC+2 schrieb Sergey:
That's odd. I was able to use your data to render a column chart: http://jsfiddle.net/6kjs401c/

Is there any chance you could post a link to a failing page? If you're not comfortable posting a link on the forum, please feel free to email me at grabks <at> google.com

On Fri, May 8, 2015 at 1:02 PM Manuel <manuel...@googlemail.com> wrote:
Sergey,

following my JSON:
{ "cols":[ {"id":"","label":"Land","type":"string"}, {"id":"","label":"Bewertung","type":"number"}, {"type":"string","role":"style"}], "rows": [{"c":[ {"v":"Neuseeland","f":null}, {"v":0.694,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Kanada","f":null}, {"v":0.6779,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Norwegen","f":null}, {"v":0.6533,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Australien","f":null}, {"v":0.6483,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Belgien","f":null}, {"v":0.5923,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Grossbritanien","f":null}, {"v":0.5427,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Schweden","f":null}, {"v":0.4668,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Frankreich","f":null}, {"v":0.3631,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Brasilien","f":null}, {"v":0.2624,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Irland","f":null}, {"v":0.2479,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Finnland","f":null}, {"v":0.2396,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Israel","f":null}, {"v":0.2105,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Dänemark","f":null}, {"v":0.2022,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Niederlande","f":null}, {"v":0.1762,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Spanien","f":null}, {"v":0.1728,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Österreich","f":null}, {"v":0.1577,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Türkei","f":null}, {"v":0.153,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Süd Afrika","f":null}, {"v":0.1274,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Luxemburg","f":null}, {"v":0.1106,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Mexiko","f":null}, {"v":0.0737,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Schweiz","f":null}, {"v":0.0587,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"USA","f":null}, {"v":0.0533,"f":null},{"v":"#0F2047","f":null}]},{"c":[ {"v":"Russland","f":null}, {"v":0.0128,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"China","f":null}, {"v":0.0104,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Italien","f":null}, {"v":0.0099,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Island","f":null}, {"v":-0.0252,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Tschechische Republik","f":null}, {"v":-0.0336,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Deutschland","f":null}, {"v":-0.0452,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Estland","f":null}, {"v":-0.0735,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Slowakei","f":null}, {"v":-0.0907,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Litauen","f":null}, {"v":-0.1032,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Lettland","f":null}, {"v":-0.1178,"f":null},{"v":"#A9B6D4","f":null}]},{"c":[ {"v":"Portugal","f":null}, {"v":-0.1207,"f":null},{"v":"#A9B6D4"
...

Andy Scott

unread,
Apr 10, 2017, 6:42:45 AM4/10/17
to Google Visualization API
Gents I have a similarly weird JSON string error coming from the Google visualisation API. However, mine isn't coming from the data I'm pulling from a service it's coming from the static options JSON string I have in my code snippet.

Here is a JS Fiddle of the example working: https://jsfiddle.net/8ynmrotc/1/

However, when I add this example to my Rails application I get a message saying invalid JSON string and with the contents of the options variable. The charts library is added to my vendor js libs and there's no backend code being called at all.

The only thing I can think that might be causing it is potentially some interaction with my jquery/jquery-ui but I see no errors and didn't think the charts/visualisation js used separate libs for calls to the gstatic API...

Any ideas what's causing this I'm totally out of ideas?

JS:

$(document).ready(function() {
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

function calculatePosition(y, a, t, v) {
return y + v*t + ((a*t)^2)/2;
}

function drawChart() {
var y = 0;
var v = 1;
var a = 2;
var data = new Array();
data[0] = new Array('Time', 'Growth');

for (var t = 1; t <= 10; t++) {
y = calculatePosition(y, a, t, v);
v = a*t;
data[t] = new Array(t, y);
}

var data = google.visualization.arrayToDataTable(data);

        // options JSON "causing" issues
var options = {
title: 'Accelerated Growth',
curveType: 'function',
legend: { position: 'bottom' }
};

var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

chart.draw(data, options);
}
});

show.html.erb

<div id="proactive-metrics-container">
<h1><%= @partner.name %></h1>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</div>

The source lib I downloaded and added to vendor pipeline: https://www.gstatic.com/charts/loader.js
Reply all
Reply to author
Forward
0 new messages