我是 JQuery 新手。我有来自服务器的 JSON 响应,我该如何解析它?
[
{
"note": {
"created_at": "2012-04-28T09:41:37Z",
"updated_at": "2012-04-28T09:41:37Z",
"text": "aaaaaaaaaaafdafasd fasfasd dfa sdfasf asdfa fasdfda",
"lng": 44.5159794497071,
"id": 7,
"deleted": false,
"user_id": 1,
"note_type": "text",
"lat": 40.1884140543842
}
},
[ ... more JSON ...]
]
我该如何解析这个?
最佳答案
您必须将请求的数据类型设置为“json”,并且数据将在您的成功回调中解析。
您目前需要了解的一切都在http://api.jquery.com/jQuery.ajax/上
这是一个非常简单的示例,说明您可以执行的操作:
$.ajax({
url: url, // the service URL. Must answer proper JSON
data: { // the parameters of the request. This should be adapted to your case
param1: value1,
param2: value2
},
dataType: "json",
type: "POST",
success: function(resultData) {
// here, resultData is your parsed json
},
error: function() {
// handle error here
}
});
关于javascript - 如何使用Jquery解析以下JSON数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10833854/