$.ajax 解析问题 (jQuery)
所以我有一个数组:
[{'key1':'a', 'key2':'b', 'ProblemKey': {'keyP1': 'c', 'KeyP2':'d'}}, {'key1':'e', 'key2': 'f', 'ProblemKey': ....}}]
当我对从 GET 响应接收到的数据(上面)执行标准 $.each 循环时,除了“problemKey”之外,所有键都正确对应于数组中每个对象的值(因为它们的值是关联数组而不是字符串?)。这些总是以未定义的形式返回。有没有办法让 $.ajax 方法正确解析这些部分?或者我应该将数据作为文本文档返回,并获取一些比 jQuery 附带的插件具有更好解析能力的第三方插件?
So I have an array:
[{'key1':'a', 'key2':'b', 'ProblemKey': {'keyP1': 'c', 'KeyP2':'d'}}, {'key1':'e', 'key2': 'f', 'ProblemKey': ....}}]
When I do the standard $.each loop through the received data (above) from my GET response, all of the keys correspond correctly to their value for each object in the array except the "problemKey"s (because their values are associative arrays and not strings?). Those always come back as Undefined. Is there any way to get the $.ajax method to parse these parts correctly? Or should I return the data as a text document and get some third party plugin that has better parsing abilities than the one that comes with jQuery already?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
$.ajax
调用中,将dataType
设置为"json"
:然后在
success
函数中您可以使用点运算符访问返回值:In your
$.ajax
call, set thedataType
to"json"
:Then in the
success
function you can access the return value with the dot operator: