0

I've the below combination of server-side and client-side json processing code. I'm able to load json data from remote url and from local .js file. But, somehow I'm unable to figure out how to load data from the serverjson object in the below code snippet.

    var json ;     

    <#list jsons as json>
             serverjson = ${json};
             console.log(serverjson);


          $.getJSON(---have to load data from json object----).done(function (jsonData) {
            var time = 0; var curc = 0; var prec = 0;
            $.each(jsonData.current.timeSeries, function(i,item){
                //console.log(jsonData.current.timeSeries[i].beginTimeSeconds+" : "+jsonData.current.timeSeries[i].endTimeSeconds+" : "+jsonData.current.timeSeries[i].inspectedCount);
                time = jsonData.current.timeSeries[i].beginTimeSeconds;
                curc = jsonData.current.timeSeries[i].inspectedCount;
                //curdata.addRows([curc]);
                curdata.push(curc)
                //data.addRows([[jsonData.current.timeSeries[i].beginTimeSeconds,jsonData.current.timeSeries[i].endTimeSeconds,jsonData.current.timeSeries[i].inspectedCount]]);

           });
</#list>

So, to conclude, I'm not passing remote url or .js file in the $.getJSON() function, I need to pass serverjson object.

Please help me how to solve this.

Thanks in advance.

1 Answer 1

1

Instead of:

$.getJSON(---have to load data from json object----).done(function (jsonData) {
     // code
});

do:

var jsonData = JSON.parse(serverjson);
// code
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, The question is a stupid one. Now I realized. In fact after posting I got this idea. I just need to copy serverjson objec to jsonData. That's all. Thanks a lot.
Yes, it depends whether serverjson is really JSON, or already a JavaScript object. If it is the first, you need JSON.parse, if it is the second, no conversion is needed. But one advise: don't call variables jsonData or serverjson if they are not strings, because then they are not JSON. JSON is a text format. JavaScript objects are not text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.