I need to put the images from JSON file to my React Native Page. Below is my code:
<View style={{ flexDirection: 'row', alignItems:'center' }}>
<Image source={{item.image}} style = {styles.imageView}/>
<View style={{ flex: 1, alignItems: "center"}}>
<Text style={styles.Address1}>{item.addr} </Text>
</View>
</View>
I can read other things from my JSOn file like item.addr is coming from json file, but not sure how to read the image. I tried writing my json file like this:
{
"addr": "124 test drive, Ring road",
"phone": "(951)-955-6200",
"LatL":"33.977880",
"Long2":"-117.373423",
"cLat": "33.931989",
"cLong": "-117.409222",
"Online": "https://www.test.org",
"image" : "require(\"CAC.png\")"
}
I also tried writing image like below in my JSON file
"image" : "require('../images/CAC.png')"
It seems, it is reading blank image: below is the screen shot:
Below code is working, but in this case, I am writing a constant image rather than reading from json file.
<Image source={require('../images/CAC.png')} style = {styles.imageView}/>
My code is in a directory called Modules that resides in project directory directory. My project name is test and my Json file is in a directory called Reducers and reducers also resides in project directory and my images are in a directory called images that also resides in the project directory. below is the path:
c:\MobileApplication\test\Modules\ServiceListDetails.js
c:\MobileApplication\test\reducers\ServiceDetails.json
c:\MobileApplication\test\images\CAC.png
My project name is test. below is my imageView style
imageView:{
width:'30%',
height:100,
margin:7,
borderRadius: 7
},
Any help will be greatly appreciated.
