2017-01-24 8 views
1

が機能していない。そして、すべての保存ファイルにJSON文字列は次のように私はPHPファイルからJSON文字列を取得しています

RNFS.writeFile(RNFS.DocumentDirectoryPath + 'info.json', responseData.toString()) 

async fetchAvailableSets(){ 
    try { 
     let response = await fetch('http://example.com/getdata.php', { 
      method: 'POST', 
      headers: { 
       'Accept': 'application/json', 
       'Content-Type': 'application/json' 
      } 

     }) 
     let responseJson = await response.json() 
     .then((responseData) => { 

      console.log(responseData) /* This displays the JSON text */ 


      RNFS.writeFile(RNFS.DocumentDirectoryPath + 'info.json', responseData) 
      .then(() => { 
       RNFS.readFile(RNFS.DocumentDirectoryPath + 'info.json') 
       .then((contents) => { 
        console.log(contents) /* Nothing is displayed */ 
       }) 
      }) 
     }) 
    } 
    . 
    . 
    . 
} 

私はにWRITEFILEラインを変更した場合私はファイルに "[オブジェクトオブジェクト]"と書かれています。これは正当なオブジェクトではなく文字列のようです。

すでに文字列であるため、文字列に変換する必要はないはずです。また、それを文字列に変換するのがなぜオブジェクトになるのかはちょっと分かりません。

私は間違っていますか?

+1

'JSON.stringify(responseData)'を実行しても同じことができますか? –

+0

@MattAftありがとうございました! – kojow7

答えて

0
JSON.stringify(responseData); 

がより適切である。

関連する問題