2017-01-06 6 views
0

.jsonファイルを読み込み、その内容を読み込もうとしています。しかし、私が得るすべては、このような出力は次のようになります。 AlertWindowネイティブインポートjsonファイルに反応して内容を確認します

これは私のコードです:それは文字列として実際のコンテンツを取得したいと思い

import movies from './movies.json'; 

    /* 
    ... 
    */ 

    function componentWillMount() { 
    return (
     fetch(movies).then((res) => res.json()).then((data) => 
     {this.setState({hugeText: data.something}); 
     }) 
    ); 
    } 
    function searchForName(){ 
    var content = componentWillMount(); 
    alert(content); 
    } 

。私はあなたがそのようcomponentWillMountを使用することができるとは思わない

+0

警告に表示されている内容を完全なコード – Codesingh

+0

を共有してください! – Codesingh

答えて

0

...

componentWillMount() { 
    fetch(movies).then((res) => res.json()).then((data) => { 
    this.setState({hugeText: data.something}); 
    }); 
} 

searchForName() { 
    alert(this.state.hugeText); 
} 
関連する問題