I have a C# method which generates a JSON string that Google charts requires. The output of such would look a little like this:
[ [{ v: 'Mike', f: 'Mike' }, '', 'The President'], [{ v: 'Jim', f: 'Jim Vice President' }, 'Mike', 'VP'], ['Alice', 'Mike', ''], ['Bob', 'Jim', 'Bob Sponge'], ['Carol', 'Bob', ''] ]
I’m trying to retrieve this data from within my Javascript using getJSON and a method which returns a JsonResult. However, the Javascript will (correctly) not parse it as an array because I’m using a string.
How can I overcome this problem? I imagine I should be generating my C# JsonResult from an array, seeing as this is what the data is. However, Google’s format doesn’t exactly lend itself well to this…
Thanks in advance.
If the text can’t be made valid JSON, you may need to use
eval…Or have it eval’d using the
Functionconstructor……but in both cases, make sure you trust the data being sent.
Both of these techniques will evaluate the string as JavaScript code, so whatever is sent will run as long as the JavaScript syntax is valid.