【发布时间】:2021-06-15 02:53:35
【问题描述】:
我正在尝试在我的应用中检索 JSON 数据。使用时返回数据成功:
<Text style={styles.font}> {item.show.name}</Text>
但我现在正尝试返回图像。 JSON中图片的正确路径是:
item.show.image.original
但我收到一条错误消息:
“Null is not a object (evaluating item.show.image.original)
我尝试过更改路径名、添加索引、将路径放入字符串中,但没有任何改变。代码如下:
<View>
{data ? (<View style={styles.resultsContainer}>
<FlatList
numColumns= '3'
data={data}
renderItem={({item}) => (
<TouchableOpacity style = {styles.show}onPress={() => navigation.navigate('Shows')}>
<View style={styles.text}>
<Text style={styles.font}> {item.show.name}</Text>
</View>
<Image
style={styles.resultImage} source={{uri: item.show.image.original }} />
</TouchableOpacity>
)}
/>
</View>
这里是 JSON
[
{
"score": 17.915743,
"show": {
"id": 5631,
"url": "https://www.tvmaze.com/shows/5631/car-sos",
"name": "Car S.O.S",
"type": "Documentary",
"language": "English",
"genres": [],
"status": "To Be Determined",
"runtime": 60,
"premiered": "2013-02-07",
"officialSite": "http://natgeotv.com/uk/car-sos",
"schedule": {
"time": "20:00",
"days": [
"Thursday"
]
},
"rating": {
"average": 7.9
},
"weight": 95,
"network": {
"id": 242,
"name": "National Geographic Channel",
"country": {
"name": "United Kingdom",
"code": "GB",
"timezone": "Europe/London"
}
},
"webChannel": null,
"externals": {
"tvrage": 35146,
"thetvdb": 266851,
"imdb": null
},
"image": {
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/100/250748.jpg",
"original": "https://static.tvmaze.com/uploads/images/original_untouched/100/250748.jpg"
}
为什么我的图像没有返回?我很困惑,因为文本完美返回,但图像却没有。
【问题讨论】:
-
如果你这样做
console.log(item.show.image)会得到什么?
标签: json image react-native null