0

This is a very simple question but I'm writing a webpage that's supposed to display the user's information. There will be fields of name, id, role, etc. I want to write setter and getter methods for the JSON that I receive from the database. For example, if I get a JSON and I want to get and display the name field, how would I write this getter method in angularJS after getting the JSON from a $resource service?

This is an example of how the JSON would look:

[{"name": "Jason"
  "date of birth": "february 23, 2985"
  ....
 }]

Again, I just want to know how to write a getter method if I wanted to get the name field.

1 Answer 1

3

Should be just like javascript.

var result = [{"name": "Jason"
  "date of birth": "february 23, 2985"
  ....
 }];

var firstResultsName = result[0].name;

But i noticed a problem with the result that you gave. You need a comma after each property.

[{"name": "Jason", <<-- this comma is necessary to work correctly.
"date of birth": "february 23, 2985",  <<-- and this one.

make sure you have commas for all but the last property.

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.