サーバーの応答から完全に作成された JSON オブジェクトを取得しています。
例えば:
{
"users": [
{
"userId": 20410,
"firstName": "Viral",
"lastName": "Shah",
"loginId": "viralp.shah@tcs.com",
"userRole": 3
},
{
"userId": 400881,
"firstName": "Viral",
"lastName": "Shah",
"loginId": "viralpshah123@gmail.com",
"userRole": 0
},
{
"userId": 425622,
"firstName": "Viral",
"lastName": "Shah",
"loginId": "viralpshah123@tcs-itontap.com",
"userRole": 0
}
]
}
以下のようにAJAXを使用してJavaScriptでこれを使用しています:
var jsonobj2 = null;
var respObj = getSearchedWPUsers(firstname, lastname, loginid); //return json response
var len = respObj.length;
jsonobj2 = eval('(' + respObj + ')');
var tablehtml = "<table><tr><td><b>First Name</td><td><b>Last Name</td><td><b>Login Id</td><td><b>Editing Rights</td></tr><tr></tr>";
for (i = 0; i < len; i++) {
tablehtml = tablehtml + "<tr>";
//--------------
tablehtml = tablehtml + "<td>";
tablehtml = tablehtml + jsonobj2.users[i].firstName;
tablehtml = tablehtml + "</td>";
//--------------
tablehtml = tablehtml + "<td>";
tablehtml = tablehtml + jsonobj2.users[i].lastName;
tablehtml = tablehtml + "</td>";
//--------------
tablehtml = tablehtml + "<td>";
tablehtml = tablehtml + jsonobj2.users[i].loginId;
tablehtml = tablehtml + "</td>";
//--------------
tablehtml = tablehtml + "<td><b>";
var role = jsonobj2.users[i].userRole;
if (role == 1 || role == 2 || role == 3) tablehtml = tablehtml + "<a href ='javascript:removeXML(" + jsonobj2.users[i].userId + ")'><u><font color='red'>Revoke access</font></a> ";
else tablehtml = tablehtml + "<a href ='javascript:generateXML(" + jsonobj2.users[i].userId + ")'><u><font color='blue'>Assign access</font></a> ";
tablehtml = tablehtml + "</td>";
tablehtml = tablehtml + "</tr>";
}
tablehtml = tablehtml + "</table>";
document.getElementById("TableHolder").innerHTML = tablehtml;
//--------------------------
以下のようなエラーがスローされます
TypeError: jsonobj2.users[i] is undefined
[Break On This Error]
tablehtml = tablehtml + jsonobj2.users[i].firstName;
で試しましたJSON.parse(serverresponse);
-- 何も起こりませんでした
助けてください