0

How to create a json like object in javascript

means:

My object look like

var abc = [{ lat: 17.3753, lag: 78.4744, count: 4 }, { lat: 17.3754, lng: 78.4744, count: 1 }]

i tried with

var feedbackData = [];

for (index in dataCollection.collection) {
    feedbackData.push({
        lat: index.split('~')[0],
        lag: index.split('~')[1],
        count: dataCollection.item(index)
    });
}

then i am sending like this JSON.stringify(feedbackData) this is not working.

how to create a object like that.

Please help

thanks in advance

8
  • How are you going to send this data? Can you show us the code that does that? Commented Sep 19, 2013 at 13:41
  • after getting all the data i am sending using JSON.stringify(feedbackData) code to another method Commented Sep 19, 2013 at 13:42
  • It might have something to do with your for(.. in ..) loop. Try using for (var i = 0; i < dataCollection.collection.length; i++){...} Commented Sep 19, 2013 at 13:42
  • is it lat and lag or lat and lng? Your data seems to be inconsistent. I suspect a typo in the field names. Commented Sep 19, 2013 at 13:42
  • can you please post a question with your answer Commented Sep 19, 2013 at 13:43

1 Answer 1

1

JavaScript objects already are JSON objects (they were the inspiration for JSON objects). The array of the object you have already contains two JSON objects.

Sign up to request clarification or add additional context in comments.

3 Comments

can you please explain how can i get a object like Please post a codethat ?
Yea, except that you can have JavaScript objects that are not valid JSON. mind blown, I know
Thanks i can wrong.Thanks for your time. sorry for use less question

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.