0

I want to create the below object dynamically in JSON as per the below format. Data will be from a different source which i will be getting from Ajax. Can you please let me know how to create the JSON dynamically.

window.store1 = new Ext.data.JsonStore({
            fields: ['name', '2008', '2009', '2010','2011', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9', 'data10', 'data11'],
            data: generateData(5, 20)
        });
3
  • 1
    I'm sorry, but I don't understand what you want to do at all. You need to provide more information. Commented Apr 12, 2012 at 15:28
  • 2
    I understand what you want to do, but the requirement is too broad. It will depend on how the data is coming back from the Ajax source, etc. A better question is... why do you want to do this on the client side? If the data is coming from an Ajax source, have it converted to JSON on the server then send it to the client. For most applications using JSON, the server provides the JSON and the client converts or otherwise uses it. Why do you want to create a JSON object on the client side? Commented Apr 12, 2012 at 15:31
  • There is no such thing as a "JSON Object". JSON is a string representation of a JavaScript object (or array). What you want to do is make a JavaScript object. What seems to be the issue, though? What you have is an object created "dynamically". What is generateData? Is that from an AJAX call? AJAX calls cannot return values, they are asynchronous. Commented Apr 12, 2012 at 15:33

1 Answer 1

1
var d = {
            fields: ['name', '2008', '2009', '2010','2011', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9', 'data10', 'data11'],
            data: 'You Data'
        }

var json = JSON.stringify(d)
Sign up to request clarification or add additional context in comments.

Comments

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.