Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

javascript - 循环遍历JSON对象列表(Loop through JSON object List)

I am returning a List<> from a webservice as a List of JSON objects.

(我从Web服务返回List <>作为JSON对象列表。)

I am trying to use a for loop to iterate through the list and grab the values out of the properties.

(我试图使用for循环迭代列表并从属性中获取值。)

This is a sample of the returning JSON:

(这是返回JSON的示例:)

{"d":[{"__type":"FluentWeb.DTO.EmployeeOrder",
 "EmployeeName":"Janet Leverling",
 "EmployeeTitle":"Sales Representative",
 "RequiredDate":"/Date(839224800000)/",
 "OrderedProducts":null}]}

So I am trying to extract the contents using something like this:

(所以我试图用这样的东西提取内容:)

function PrintResults(result) {

for (var i = 0; i < result.length; i++) { 
    alert(result.employeename);
}

How should this be done?

(该怎么做?)

  ask by Nick translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Be careful, d is the list.

(小心, d是列表。)

for (var i = 0; i < result.d.length; i++) { 
    alert(result.d[i].employeename);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...