多个返回键 json
multiple returned keys json
我有一个 joomla 站点 运行 k2 并通过在字符串末尾添加格式=json 从中提取信息:https://www.example.com/posts?format=json 输出如下所示:
{
site: {
url: "https://www.example.com",
name: "mySite"
},
category: {
id: "67",
name: "Gauteng",
alias: "gauteng",
link: "/tna/provincial/gauteng.html",
parent: "66",
extraFieldsGroup: "0",
image: null,
ordering: "1",
events: {
K2CategoryDisplay: ""
},
chidlren: []
},
items: [{
id="1",
title="The Title",
body="body content here..."
},
{
id="2",
title="The Title",
body="body content here..."
}
}
现在我正在为此创建服务,只想访问 "items"。
.factory('Posts', function($http) {
var posts = [];
return {
getPosts: function(){
return $http.get("https://www.example.com/posts?format=json").then(function(response){
posts = response;
return posts;
});
},
getPost: function(index){
return posts[index];
}
}
});
虽然它似乎没有用。有什么方法可以通过通话访问 "items" 吗?
你的 post 语法应该是 posts = response.data.items
return $http.get("https://www.example.com/posts?format=json").then(function(response){
posts = response.data.items; //items here
return posts;
});
我有一个 joomla 站点 运行 k2 并通过在字符串末尾添加格式=json 从中提取信息:https://www.example.com/posts?format=json 输出如下所示:
{
site: {
url: "https://www.example.com",
name: "mySite"
},
category: {
id: "67",
name: "Gauteng",
alias: "gauteng",
link: "/tna/provincial/gauteng.html",
parent: "66",
extraFieldsGroup: "0",
image: null,
ordering: "1",
events: {
K2CategoryDisplay: ""
},
chidlren: []
},
items: [{
id="1",
title="The Title",
body="body content here..."
},
{
id="2",
title="The Title",
body="body content here..."
}
}
现在我正在为此创建服务,只想访问 "items"。
.factory('Posts', function($http) {
var posts = [];
return {
getPosts: function(){
return $http.get("https://www.example.com/posts?format=json").then(function(response){
posts = response;
return posts;
});
},
getPost: function(index){
return posts[index];
}
}
});
虽然它似乎没有用。有什么方法可以通过通话访问 "items" 吗?
你的 post 语法应该是 posts = response.data.items
return $http.get("https://www.example.com/posts?format=json").then(function(response){
posts = response.data.items; //items here
return posts;
});