I'am trying to access the content of a JSON file i just wrote with RNFS. I tried different ways, import, json-loader etc without success.
I write the file like :
var obj = {
date: moment().format(),
counter: 0 };
var json = JSON.stringify(obj);
RNFS.writeFile(path, json, 'utf8')
.then((success) => {
count++;
console.log('FILE WRITTEN! : ');
})
.catch((err) => {
console.log(err.message);
});
Then i proceed to try to read it
var path = RNFS.DocumentDirectoryPath + '/test.json';
const cFile = RNFS.readFile(path, 'utf8');
Sadly i only get a 'promise' but can't seem to access directly the data. I get this kind of result in console.
Promise {_40: 0, _65: 0, _55: null, _72: null}
_40:0
_55:"{"date":"2018-04-11T10:52:52+02:00","counter":0}"
_65:1
_72:null
__proto__:Object
And i would like to access the date field, just like cFile.date
Any help welcome thanks you