2014-06-13 38 views
0

我使用.NET MVC4内部对象如何获得价值通过Json的

我用javascript函数如下:

function ShowDomainComponentDetail(compCode) { 
     alert(compCode); 
     $.ajax({ 
      url: "/PP/getDomainComponentDetailWithDomain", 
      data: { 
       'ComponentCode': compCode 
      }, 
      dataType: "json", 
      type: 'POST', 
      cache: false, 
      success: function (_responseData) { 
       $('#divShowDomainCompDetail').show(); 
       alert(_responseData.Data) 

      }, 
      error: function() { 
       // 
      } 
     }); 
    } 

成功后我得到的名单。NET为:

IdObservation=1, ObservationName="Started" , ObsType="Announced"; 
IdObservation=2, ObservationName="Not Started" , ObsType="Un Announced"; 
IdObservation=3, ObservationName="Declared" , ObsType="Announced"; 

我的问题是我不是abl; e访问Ajax成功块内的这个列表。

我如何可以访问此列表为:

alert(_responseData.IdObservation); 
alert(_responseData.ObservationName); 

(而且我要去这个分配到标签)。

请帮帮我。

编辑1:

我Serverside集团函数返回列表:

public JsonResult getDomainComponentDetailWithDomain(string ComponentCode) 
     { 
      try 
      { 
       List<TEAMS_PP.Entity.correlations> compDetail_list = new correlation().getDomainComponentDetailswithDomain(ComponentCode); 
       return Json(compDetail_list); 
      } 
      catch (Exception) 
      { 
       List<TEAMS_PP.Entity.correlations> BlankList = new List<TEAMS_PP.Entity.correlations>(); 
       return Json(BlankList); 
      } 
     } 
+0

你是如何从服务器返回列表? – James

+0

@James PLZ看EDIT1 –

+0

酷只是确保你正确地发回它,你的结果很简单的对象数组(你可以看到,如果你使用调试器)。请参阅下面的@ Bhushan的答案。 – James

回答

3

与数据使用索引对象象下面这样:

alert(_responseData[0].IdObservation); 

通过对象循环和获取值为每个对象。

+0

Dhanyawad saheb !!!工作zall ... 7分钟madhye接受karato回答:) –

+0

tumacha swagat aahe :) –

+0

7分钟zalet rao ... ata接受卡拉。 –

1

可以使用每个$迭代它

$.each(_responseData, function (key, value) { 
         var arr = value.IdObservation; 
        });