Javascript TypeError: JSON array object is undefined

I am getting a perfectly created JSON object from server response. For example: { "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 } ] } I am using this in JavaScript using AJAX like below: var jsonobj2 = null; var respObj = getSearchedWPUsers(firstname, lastname, loginid); //return json response var len = respObj.length; jsonobj2 = eval('(' + respObj + ')'); var tablehtml = ""; for (i = 0; i < len; i++) { tablehtml = tablehtml + ""; //-------------- tablehtml = tablehtml + ""; //-------------- tablehtml = tablehtml + ""; //-------------- tablehtml = tablehtml + ""; //-------------- tablehtml = tablehtml + ""; tablehtml = tablehtml + ""; } tablehtml = tablehtml + "
First NameLast NameLogin IdEditing Rights
"; tablehtml = tablehtml + jsonobj2.users[i].firstName; tablehtml = tablehtml + ""; tablehtml = tablehtml + jsonobj2.users[i].lastName; tablehtml = tablehtml + ""; tablehtml = tablehtml + jsonobj2.users[i].loginId; tablehtml = tablehtml + ""; var role = jsonobj2.users[i].userRole; if (role == 1 || role == 2 || role == 3) tablehtml = tablehtml + "Revoke access "; else tablehtml = tablehtml + "Assign access "; tablehtml = tablehtml + "
"; document.getElementById("TableHolder").innerHTML = tablehtml; //-------------------------- It throws errors like below > `TypeError: jsonobj2.users[i] is undefined` > `[Break On This Error]` > `tablehtml = tablehtml + jsonobj2.users[i].firstName;` tried with `JSON.parse(serverresponse);` -- nothing happened Please help

以上就是Javascript TypeError: JSON array object is undefined的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏