如何在 jQuery Ajax 成功回调中处理我的 JSON 数据?
如果我有一个ajax调用:
$.ajax({
url: url,
dataType: 'json',
data: data,
success: function(json_data){
//What's the efficient way to extract the JSON data and get the value
}
});
服务器向我的js返回了以下JSON数据
{"contact":[{"address":[{"city":"Shanghai","street":"Long
Hua Street"},{"city":"Shanghai","street":"Dong Quan
Street"}],"id":"huangyim","name":"Huang Yi Ming"}]}
在我的jQuery AJAX成功回调函数中,如何提取“name”的值,值“地址”(这是一个对象列表)优雅吗?
我对 javascript 中的 jQuery 和 JSON 数据处理没有经验。因此,我想就如何有效地处理这些数据提出一些建议。谢谢。
If I have a ajax call:
$.ajax({
url: url,
dataType: 'json',
data: data,
success: function(json_data){
//What's the efficient way to extract the JSON data and get the value
}
});
Server returned to my js the following JSON data
{"contact":[{"address":[{"city":"Shanghai","street":"Long
Hua Street"},{"city":"Shanghai","street":"Dong Quan
Street"}],"id":"huangyim","name":"Huang Yi Ming"}]}
In my jQuery AJAX success callback function, how to extract the value of "name", value of "address" (which is a list of object) elegantly?
I am not experienced with jQuery and JSON data handling in javascript. So, I would like to ask some suggestions on how to handle this data efficiently. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 字符串被解析为 JavaScript 对象/数组。因此,您可以像访问任何对象属性、数组元素一样访问值:
访问每个地址内的值,您可以迭代数组:
如果您对 JavaScript 没有太多经验,我建议 阅读本指南。
A JSON string gets parsed into a JavaScript object/array. So you can access the values like you access any object property, array element:
Do access the values inside each address, you can iterate over the array:
If you have not so much experience with JavaScript, I suggest to read this guide.