jQuery获取JSON值 [英] jQuery get json values
问题描述
我正在尝试通过jQuery json为我的系统获取草稿= false 的最后 3篇博客文章,并遵循一些在线找到但没有运气的教程,并使用以下键: /p>
"sl" 这是json输出 我当前的脚本在下面,但是我很确定自己做错了很多事. 任何帮助将不胜感激. 尝试这种方式: I'm trying to fetch the last 3 blog posts with the draft = false for my system via jQuery json and following some tutorials if found online but without luck, and with the following keys: "slug" Here is the json output My current script is below, but i'm pretty sure that i'm doing a lot of things wrong. Any help would be so much appreciated. try this way: 这篇关于jQuery获取JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
已更新"
标题"
内容"
草稿=假" {
"posts":[
{
"Blog":{
"id":"1252",
"client_id":"1432",
"slug":"my-blog-slug",
"last_updated_by":"614",
"draft":false,
"created":"2014-09-17 11:18:39",
"updated":"2014-09-17 11:18:39",
"locale":"isl",
"title":"This is the blog title",
"content":"<p>My excellent content.<\/p>",
"author":"John Doe"
},
"UpdatedBy":{
"id":"614",
"name":"John Doe"
}
}
]
}
<script>
$(document).ready(function() {
$.ajax({
url: "blogs.json",
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
$('#results').html('Title: ' + json.created + '<br />Description: ' + json.content);
}
});
});
</script>
<div id="results"></div>
JS
$(document).ready(function() {
$.ajax({
url: "blogs.json",
dataType: "json",
success: function(data) {
var json = $.parseJSON(data);
$.each(json.posts, function(){
$('#results').html('Title: ' + this.Blog.title + '<br />Description: ' + this.Blog.content);
});
}
});
});
"updated"
"title"
"content"
"draft = false"{
"posts":[
{
"Blog":{
"id":"1252",
"client_id":"1432",
"slug":"my-blog-slug",
"last_updated_by":"614",
"draft":false,
"created":"2014-09-17 11:18:39",
"updated":"2014-09-17 11:18:39",
"locale":"isl",
"title":"This is the blog title",
"content":"<p>My excellent content.<\/p>",
"author":"John Doe"
},
"UpdatedBy":{
"id":"614",
"name":"John Doe"
}
}
]
}
<script>
$(document).ready(function() {
$.ajax({
url: "blogs.json",
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
$('#results').html('Title: ' + json.created + '<br />Description: ' + json.content);
}
});
});
</script>
<div id="results"></div>
JS
$(document).ready(function() {
$.ajax({
url: "blogs.json",
dataType: "json",
success: function(data) {
var json = $.parseJSON(data);
$.each(json.posts, function(){
$('#results').html('Title: ' + this.Blog.title + '<br />Description: ' + this.Blog.content);
});
}
});
});