0

I'm trying to do some stuff with ajax in my web page. But what is my problem here is, I have one array in my json result. I don't know to retrieve the data inside my array in jquery.

Here is my JSON :

{"res":{"tname":"my template","process":["software requirement analysis","efrwefgwerg","ergerger","ewrgerger","erwgrewgre"]}}

I wan't to get the data inside "process"

And what I tried is:

var app;
$.each(data.res.process,function(i,data){app='<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>'+data[i]+'<button aria-hidden="true" data-dismiss="modal" class="proclose close" type="button">×</button></li>';
$('#info .processDet').append(app);});

This code gives single character from specified index of that of index. I mean, If it is data[0] then it gives s. And if it is data[1] then it gives f.

Please anyone help me to solve this issue.

James
  • 2,874
  • 4
  • 30
  • 55
  • possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Felix Kling Jan 15 '14 at 17:31
  • @ Felix Kling If it is duplicate, Then it is ok, after hours of research I posted this question here. – James Jan 15 '14 at 17:46

1 Answers1

2

Change data[i] to data

var app;
$.each(data.res.process,function(i,data){app='<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>'+data+'<button aria-hidden="true" data-dismiss="modal" class="proclose close" type="button">×</button></li>';
$('#info .processDet').append(app);});

Take a look at http://api.jquery.com/jquery.each/

You can try this also, If you want

var app;
$.each(data.res.process,function(i,data){app='<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>'+data.res.process[i]+'<button aria-hidden="true" data-dismiss="modal" class="proclose close" type="button">×</button></li>';
$('#info .processDet').append(app);}); 
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188