-7

I have a json data like this in jQuery

{"res":"123","pgm":"bar","digit":"demo"}

Now I have to alert the res and pgm.

How i retrieve these two from the json data

Thanks

user3847937
  • 109
  • 5
  • 17
  • Do you have a JSON string or an object? You probably need to show the context to solve your *actual* problem. – JJJ Nov 26 '14 at 09:15
  • alert(response.res) gives undefined – user3847937 Nov 26 '14 at 09:23
  • As I said, you need to give context, i.e. where do you get the data, what does it look like... We can't know why it would give undefined if you don't show your code. – JJJ Nov 26 '14 at 20:40

2 Answers2

2

Do it like:

var data = {"res":"123","pgm":"bar","digit":"demo"};

alert(data.res);

alert(data.pgm);

Working Demo

Nice tutorial about accessing JSON data.

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
0
var json = {"res":"123","pgm":"bar","digit":"demo"};

alert(json.res+" - "+json.pgm);
Raúl Monge
  • 223
  • 2
  • 7