Howdy,

The requirements for proper JSON syntax are strict, and not the same as
JavaScript Object literals.  The names of properties must be quoted with
double quotes, so you might prefer to use single quotes for the outermost
string quoting and double quotes inside.  E.g.
var haha =
  '{' +
  '  "cols":[{"id": "task", ...}]' +
  '}';

dan

On Thu, Dec 20, 2012 at 5:34 AM, ah89 <[email protected]> wrote:

> Hey,
>
> I am trying to convert an array to a JSON string, which can be assigned to
> a Google Visualization datatable.
> However, whatever I try, I keep getting errors. Even with the example of
> Google Visualization API!
>
> This is what I have:
>
> String haha =  "{" +
>>                     "       cols: [{id: 'task',  label: 'Task',
>> type: 'string'}," +
>>                     "              {id: 'hours', label: 'Hours per Day',
>> type: 'number'}]," +
>>                     "       rows: [{c:[{v: 'Work'},     {v: 11}]}," +
>>                     "              {c:[{v: 'Eat'},      {v: 2}]}," +
>>                     "              {c:[{v: 'Commute'},  {v: 2}]}," +
>>                     "              {c:[{v: 'Watch TV'}, {v:2}]}," +
>>                     "              {c:[{v: 'Sleep'},    {v:7,
>> f:'7.000'}]}" +
>>                     "             ]" +
>>                     "     }";
>>
>
>
> JSP:  var view = new google.visualization.DataTable(${chartData});
>
> What I get is an error, telling me that the JSON format is invalid.
>
> The goal is to save a hashmap to a datatable with JSON (hashmap contains a
> category and a value). The above example was used as I cannot seem to build
> a proper JSON format myself. But this doesn't work as well.
>
> Hopefully someone can help me. Thanks in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-visualization-api/-/c4MMELWfEekJ.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-visualization-api?hl=en.
>



-- 
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>  -
978-394-1058
[email protected] <[email protected]>   562D 5CC, Cambridge MA
[email protected] <[email protected]> 9 Juniper Ridge
Road, Acton MA

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to