reactjsreact-nativereact-native-fetch-blob

How can i use RN-Fetch-Blob to read json from sdcard


I have a noob question, I'm trying to read the movies.json of Facebook but from a sdcard.. i'm using RN-Fetch-Blob

RNFetchBlob.fs.readFile("file:///storage....", 'utf-8')
.then((data) => {
let id0 = data.movies[0].id;
})

but this is not working, how is the right way to read the id ?


Solution

  • the type of data is string so you need to use JSON.parse(data)

    RNFetchBlob.fs.readFile("file:///storage....", 'utf-8')
    .then((data) => {
    const newData = JSON.parse(data);
    newData.movies[0].id;
    })