我想打開我在 react-native 中創建的 data.json 檔案中的鏈接,我不知道該怎么做,你能幫幫我嗎?
<TouchableOpacity
style={styles.play}
onPress={() => Linking.openURL('props.song.musicUrl') }
>
<Text style ={styles.play_button}>Press Here</Text>
`{“身份證”:0,
"imageUrl":"https://i.pinimg.com/564x/94/28/8f/94288fe9af3ede8f4e07505da921f373.jpg",
"musicUrl":"https://www.youtube.com/watch?v=s6vXWtNZu0c"
},`
uj5u.com熱心網友回復:
執行此操作分為三個步驟(我認為您已經實作了 1 和 2):
- 首先讀取json檔案的內容
- 從 json 中獲取鏈接
- 打開鏈接
Linking
讀取 json 檔案的內容從本地 json 檔案中獲取資料
const customData = require('./customData.json');從 json 中獲取鏈接
const link = customData.musicUrl使用鏈接
Linking.openURL(link)
在你的情況下,
Linking.openURL(props.song.musicUrl) // <- Remove quotes
由于添加引號會創建一個字串,因此您嘗試打開鏈接'props.song.musicUrl'而不是 JSON 中的鏈接。
你可以在這里尋找指導(OpenURL)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418409.html
標籤:
