0

I'm not really good with JSON; maybe I didn't get the JSON concept so well to get out of this, so I'm asking.

I have a function in AngularJS that contains an array; this array should be automatically filled with content from a JSON page in my server. The array is composed by object made in this way:

var a = [{ id: 0, name: '', date:'', content: ''}, ...]

My question is: how should create the JSON object to respect my array syntax?

1 Answer 1

2

Just use the function built into JavaScript to convert data structures to JSON:

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

7 Comments

I don't see how this answers the question. OP wants to design a JSON response and use it to populate an array, not turning a data structure into JSON... Maybe I misunderstood the question though.
@PeterHerdenborg — The OP said they had an array which contains some objects and wanted to create JSON. It could be interpreted that way too though, it is not a clear question.
Ok (thank you for the quick answer), now i got the JSON object, but how can i trasform the string in array using $http.get('myUrl.json'), where myUrl is where my file is.
JSON.parse(yourstring)
@PeterHerdenborg you got the point. If i have the JSON object, how can i turn back into array?
|

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.