如何在json结果中得到对象属性。这个属性是数组,我想得到这个数组值

时间:2018-02-04 08:57:56

标签: javascript arrays json angular typescript

这个ombdapi结果

{Search: Array(10), totalResults: "340", Response: "True"}

我想要这个值

0:{
  Title: "Batman Begins",
  Year: "2005", 
  imdbID: "tt0372784", 
  Type: "movie", 
  Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
}

1 个答案:

答案 0 :(得分:0)

{Search: Array(10), totalResults: "340", Response: "True"}

假设您在一个名为varibale

dataObj中拥有所有这些内容

然后你可以像这样访问数组值:

dataObj.Search[0] , dataObj.Search[1] ..

和属性如:

dataObj.totalResults , dataObj.Response

var dataObj = {
    Search : [{
    Title: "Batman Begins",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins2",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begin3",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins4",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins5",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins6",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins7",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins8",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins9",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
},
{
    Title: "Batman Begins10",
    Year: "2005", 
    imdbID: "tt0372784", 
    Type: "movie", 
    Poster: "https://images-na.ssl-images-amazon.com/images/M/M…jcxYzVmXkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg"
}]
, totalResults: "340", Response: "True" }

dataObj.Search.forEach(movie => {
  console.log(movie.Title);
})