类型为NSDictionary的React Native JSON值无法转换为NSString

Ste*_*rth 3 javascript json react-native

我要开发的React Native(0.38.0版本)应用程序存在问题。我基本上在学习。

我正在从自定义API端点获取JSON。我设法遍历了JSON并输出了一些数据,但是问题是string链接到图像。我不断收到错误:

JSON Value of { robj = "https://example.com/img.jpg" } type NSDictionary Cannot be converted to NSString.
Run Code Online (Sandbox Code Playgroud)

在Google周围有一个侦察员之后,我看不出问题的正面或反面。

有人能指出我正确的方向吗?

var api = {
  getData() {
    var url = 'https://example.com/api/json/'
    return fetch(url).then((res) => res.json())
  }
}

class GetCategories extends Component {
  constructor(props) {
    super(props)
    this.state = {
      categories: []
    }
  }

  componentWillMount() {
    api.getData().then((res) => {
      this.setState({
        categories: res
      })
    })  
  }

  render() {
    var catLoop =this.state.categories.map(function(obj, index){
      var catTitle = '',
          catImage = '';

      catTitle = obj.title;
      catImage = obj.image;

      return (
        <View key={index}>
          <Image source={{uri: {catImage}}} style={{width: 400, height: 400}}>
            <Text>{catTitle}</Text>
          </Image>
        </View>
      )

    });

    return <View>{catLoop}</View>
  }
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*man 5

这应该可以解决您的问题...

<Image source={{uri: catImage}} style={{width: 400, height: 400}}>
     <Text>{catTitle}</Text>
</Image>
Run Code Online (Sandbox Code Playgroud)