0

I have JSON like this:

data {
  data1 = 'test',
  data2 = 'test2',
  data3 = 'test3'
}

and I have this data in my $scope.myJsonData.

How I can read what is inside data2? Is the best way to do this to it like this {{ myJsonData.data[1] }} or is there better ways to do this? Can I somehow read it with name (data2)?

Sorry if this was bad explanation, my english isn't very good. Ask if you need more information.

2
  • 1
    That is not valid json.. It should be data1: 'test', etc (with colons) Commented Apr 12, 2016 at 17:47
  • @Jis0 I think you should learn the fundamentals of Javascript before you try to get into AngularJS. Commented Apr 12, 2016 at 19:23

2 Answers 2

1

At first the json data which you had given is not correct json format,

I think your json is

data { 
'data1' : 'test',
'data2' : 'test2',
'data3' : 'test3' 
}

You can read the data2 like this

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

Comments

0

data1, data2 etc are keys, so to access data2's value simply write

var myvalue = data.data2

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.