我正在使用.NET MVC4
我使用了如下的 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";
我的问题是我无法访问 Ajax 成功 block 内的此列表。
我如何访问此列表:
alert(_responseData.IdObservation);
alert(_responseData.ObservationName);
(此外,我将把它分配给标签)。
请帮助我。
编辑 1:
我的服务器端函数返回列表:
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);
}
}
最佳答案
将索引与数据对象一起使用,如下所示:
alert(_responseData[0].IdObservation);
循环遍历对象并获取每个对象的值。
关于c# - 如何获取通过Json获取的对象内部的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24203639/