Assigning json to variable

18,509

Ok, problem solved. Apparently you have to use JSON.parse(). How it's done is explained here.

Share:
18,509

Related videos on Youtube

LarsVegas
Author by

LarsVegas

SOreadytohelp

Updated on June 21, 2022

Comments

  • LarsVegas
    LarsVegas 7 months

    Ok, some explanation. Even though I don't think it has anything to do with the problem itself. I have a small django project that maps some data using leaflet. On a mouseover some ajax functionality is added, using the dajax(which is a "lightweight library to implement AJAX inside django projects") framework. The call itself looks like this:

    dajax.add_data(simplejson.dumps(series), 'my_test_flot')
    

    My js function receives json data which looks like this (using alert)

    [{"color": "#dddd00", 
    "data": [[-0.5, -20.5]], 
    "label": "Tweede Zandlaag"}]
    

    The object has more data to it but the problem is not with the object. When I copy/paste the data directly into the function var series = [] the behaviour is as aspected. As aspected means, the graph I'm drawing with flot is actually being drawn. Otherwise the graph remains empty.

    function my_test_flot(dat) {
        function MyFormatter(v, xaxis) {
            return " ";
        }
        $(function () {
            alert(dat)
            var series = dat; // here lies the problem, but why?
            ...
    

    Can anyone help?

Related