내 코드는 여기에있는 객체의 수를 계산하고 싶습니다.자바 스크립트에서 객체를 계산하는 방법
eval 함수를 사용하면 요소를 가져올 수 있었지만이 경우 전체 개체 수를 계산하는 방법을 알지 못합니다. 아무도 나를 도울 수 있습니까 ??
var txt = '{
"employees": [{
"a": "wkn",
"d": "Wipro Technologies \u2013 IT Services, Product Engineering Solutions, Technology Infrastructure Services, Business Process Outsourcing, Consulting Services",
"n": "",
"u": "http://wipro.com/",
"t": ["outsourcing", "offshore", "india"],
"dt": "2009-06-26T10:26:02Z"
}, {
"a": "shaktimaan",
"d": "Wipro Technologies \u2013 IT Services, Product Engineering Solutions, Technology Infrastructure Services, Business Process Outsourcing, Consulting Services",
"n": "Wipro Technologies is the No 1 provider of integrated business, technology and process solutions on a global delivery platform.",
"u": "http://wipro.com/",
"t": ["Indian", "IT", "Services", "Companies"],
"dt": "2011-09-16T17:31:25Z"
}, {
"a": "tonemcd",
"d": "Offshore Outsourcing | IT Services",
"n": "",
"u": "http://wipro.com/",
"t": ["outsourcing", "IT"],
"dt": "2007-11-04T03:53:18Z"
}]
}'; //added \n for readability
var obj = eval ("(" + txt + ")");
document.getElementById("fname").innerHTML=obj.employees[1].a
document.getElementById("lname").innerHTML=obj.employees[1].u
이
내가 이것을 가지고 응답입니다 :First Name: shaktimaan
Last Name: http://wipro.com/
나는 elemtns를 가져올 수 있었다,하지만 난 개체 수를 원한다.
eval을 사용하지 마십시오. JSON.parse를 사용하십시오. –