2017-08-08 17 views
1

(何らかの種類のローカルリソースのような)すべてのjsファイルの間にある.csvファイルを解析する必要があります。 ジョブ> Papaparseを実行するライブラリが見つかりました。しかし、Javascript環境との非互換性のために私のローカルファイルを "ダウンロード"できないようです。反応ネイティブのJSON以外のローカルファイルにアクセスする方法

私は何とかローカルのCSVファイルの内容をpapaparseに文字列として渡すことができたらうまくいくと思います。しかし、私はローカルのcsvファイルの内容を反応ネイティブの変数の中に入れる方法を理解できません。 提案がありますか?

編集: 私はreact-native-fsで試してみました。 08-11 14:53:14.524 17058 17202 I ReactNativeJS: [ { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'AndroidManifest.xml', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//AndroidManifest.xml', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'META-INF', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//META-INF', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'assets', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//assets', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'classes.dex', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//classes.dex', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'lib', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//lib', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'res', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//res', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] }, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: { ctime: null, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: mtime: Invalid Date, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: name: 'resources.arsc', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: path: '//resources.arsc', 08-11 14:53:14.524 17058 17202 I ReactNativeJS: size: 0, 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isFile: [Function: isFile], 08-11 14:53:14.524 17058 17202 I ReactNativeJS: isDirectory: [Function: isDirectory] } ]

フォルダは常に空である私の資産のように思える:これは>出力 - 私はアンドロイド/ srcに/メイン/資産の下で私のCSVファイルを置く/及び RNFS.readDirAssets('/');

でアクセスしてみてください。

+0

https://github.com/itinance/react-native-fs – SwiftsNamesake

+0

速い返答をありがとう。私はすでにこのライブラリで試しましたが、私はどのように私のCSVファイルを指すかを理解していませんでした。他のjsファイルと一緒に入れると、私の.apkの中にパッケージ化されていませんか? –

+0

iOSとAndroid用のREADMEには、使用例があります。 – SwiftsNamesake

答えて

1

私はcsvファイルにアクセスするために管理してきました:

内部に置い:

android/app/src/main/assets/myFile.csv 

私はcsvファイルを取得することができた(私は、資産は自分自身をフォル​​ダ作成しました)次のコードの文字列として-data:

const csvFile = RNFS.readFileAssets('myFile.csv', 'ascii').then(file => { 
      return file; 
     }); 

私の場合、ファイルはASCIIエンコードされています私は2番目の引数としてエンコーディング 'ascii'を入れました。さもなければ、私は "無効継続バイト"と言うエラーを受け取ります。

関連する問題