Can';t使用React native从文件中提取.json内容

Can';t使用React native从文件中提取.json内容,json,react-native,Json,React Native,我正在尝试提取此.json文件(colors.json)的内容。我真的不知道我的代码有什么问题。无法在文本标记中找到正确的调用 react-native-cli: 2.0.1 react-native: 0.39.0 Quote.js 输出图像(编辑) 您需要在render()方法中的colors数组上执行循环,以显示每种颜色的hexValue render () { return ( <View style={styles.container}> <

我正在尝试提取此
.json
文件
(colors.json)
的内容。我真的不知道我的代码有什么问题。无法在文本标记中找到正确的调用

react-native-cli: 2.0.1
react-native: 0.39.0
Quote.js 输出图像(编辑)

您需要在render()方法中的colors数组上执行循环,以显示每种颜色的
hexValue

render () {
  return (
    <View style={styles.container}>
      <Text style={[styles.author, styles.text]}>Denise Lee Yohn</Text>
      {
        colors.colorsArray.map((color, index) => {
          return <Text key={index} style={styles.quote}>{color.hexValue}</Text>;
        })
      }        
    </View>
  );
}
render(){
返回(
丹尼斯·李·尤恩
{
colors.colorsArray.map((颜色,索引)=>{
返回{color.hexValue};
})
}        
);
}

您需要在render()方法中的colors数组上执行循环,以显示每种颜色的
hexValue

render () {
  return (
    <View style={styles.container}>
      <Text style={[styles.author, styles.text]}>Denise Lee Yohn</Text>
      {
        colors.colorsArray.map((color, index) => {
          return <Text key={index} style={styles.quote}>{color.hexValue}</Text>;
        })
      }        
    </View>
  );
}
render(){
返回(
丹尼斯·李·尤恩
{
colors.colorsArray.map((颜色,索引)=>{
返回{color.hexValue};
})
}        
);
}

这似乎不起作用。屏幕上根本没有写任何东西。在将上述代码放入文件之前,是否需要声明任何内容?(我已经重新启动了服务器)。只要用上面的代码替换render(),它就可以正常工作了。如果它仍然不起作用,你能截图显示什么吗?输出的截图在问题中。它还显示
从'./colors.json'导入颜色
现在是公认的语法,而不是
var colors=require('./colors.json')这似乎不起作用。屏幕上根本没有写任何东西。在将上述代码放入文件之前,是否需要声明任何内容?(我已经重新启动了服务器)。只要用上面的代码替换render(),它就可以正常工作了。如果它仍然不起作用,你能截图显示什么吗?输出的截图在问题中。它还显示
从'./colors.json'导入颜色
现在是公认的语法,而不是
var colors=require('./colors.json')
render () {
  return (
    <View style={styles.container}>
      <Text style={[styles.author, styles.text]}>Denise Lee Yohn</Text>
      {
        colors.colorsArray.map((color, index) => {
          return <Text key={index} style={styles.quote}>{color.hexValue}</Text>;
        })
      }        
    </View>
  );
}