React Native Json取不出值问题



  • 代码如下
    fetchData(){
    fetch('http://facebook.github.io/react-native/movies.json')
    .then((response) => response.json)
    .then((jsondata) => {
    console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
    console.log("接收到的为:"+jsondata.title)
    return jsondata.movies
    })
    .catch((error) => {
    console.warn(error);
    });
    }

    其中,json格式为:
    {
    "title": "The Basics - Networking",
    "description": "Your app fetched this from a remote endpoint!",
    "movies": [
    { "title": "Star Wars", "releaseYear": "1977"},
    { "title": "Back to the Future", "releaseYear": "1985"},
    { "title": "The Matrix", "releaseYear": "1999"},
    { "title": "Inception", "releaseYear": "2010"},
    { "title": "Interstellar", "releaseYear": "2014"}
    ]
    }

    但是输出结果为:
    [tid:com.facebook.react.JavaScript] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    2016-09-23 10:55:03.884 [info][tid:com.facebook.react.JavaScript] 接收到的为:undefined


  • administrators

    @jjjjc 说:

    .then((response) => response.json)

    .then((response) => response.json())



  • @sunnylqm
    哦哦这样啊。。。。真是太感谢了


登录后回复