【发布时间】:2021-06-22 19:52:46
【问题描述】:
我尝试从 api 获取 URI 图像,但它抛出了以下错误:
我一直在寻找这些信息,但找不到像我这样的案例
它不显示图像,但如果它传递数据
这是我的 api:
{
"Home": [
{ "id": "1",
"LinkHome":"https://telesistema11.com.do/tn-deportes/futbol/la-quinta-jornada-de-la-ldf-iniciara-este-proximo-jueves",
"URLHome":"{uri: 'https://telesistema11.com.do/storage/app/uploads/public/609/b45/eab/thumb_46456_932_582_0_0_crop.jpeg'}"
}
],
"TSTA": [
{ "id": "1",
"LinkTSTA":"",
"URLTSTA":""
}
],
"Radio": [
{ "id": "1",
"LinkRadio":"",
"URLRadio":""
}
]
}
这是我的代码:
function Getdatajson(){
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
fetch('http://72.44.48.164/wp-content/themes/tn/json/PublicidadTeleStream.json')
.then((response) => response.json())
.then((json) => setData(json.Home))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
}, []);
return (
<View style ={styles.bannerHome}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<TouchableOpacity style={{backgroundColor:'red'}} onPress={()=>
Linking.openURL("item.LinkHome")
}>
<Image
style={styles.imgad}
source={item.URLHome}
/>
</TouchableOpacity>
)}
/>
)}
</View>
)
}
我是新手反应原生,所以我不知道问题是什么 请问我需要帮助。
【问题讨论】:
-
请不要在图片中发布代码。请编辑问题并提供基于文本的minimal reproducible example
-
这意味着您将
source={item.URLHome}传递给Image组件,这不是一个有效的道具。Image组件的实现在哪里?确保您的Image组件作为该道具。 -
URLHome 应该是 Object
{ uri: 'https://telesistema11.com.do/storage/app/uploads/public/609/b45/eab/thumb_46456_932_582_0_0_crop.jpeg' }而不是 String 值 -
你好,我已经进行了更改并且工作正常,但是当我生成 apk 时,它没有显示我从 Json 带来的图像。你知道这可能是什么吗? @JimboMagusib
-
这可能有很多原因。如果 ios 存在可以通过
npx react-native-fix-image修复的问题,或者它可能是源 URI 标头或样式。
标签: javascript json react-native jsx