Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NSDictionary类型的React本机JSON值无法转换为NSString_Javascript_Json_React Native - Fatal编程技术网

Javascript NSDictionary类型的React本机JSON值无法转换为NSString

Javascript NSDictionary类型的React本机JSON值无法转换为NSString,javascript,json,react-native,Javascript,Json,React Native,我试图开发的React Native(0.38.0版)应用程序有问题。我基本上是边走边学 我正在从自定义API端点获取JSON。我已经成功地循环了JSON并输出了一些数据,但问题在于链接到图像的字符串。我不断得到错误: JSON Value of { robj = "https://example.com/img.jpg" } type NSDictionary Cannot be converted to NSString. 在谷歌周围进行了一次侦察之后,我看不出这个问题的头绪 谁能给我指一

我试图开发的React Native(0.38.0版)应用程序有问题。我基本上是边走边学

我正在从自定义API端点获取JSON。我已经成功地循环了JSON并输出了一些数据,但问题在于链接到图像的
字符串。我不断得到错误:

JSON Value of { robj = "https://example.com/img.jpg" } type NSDictionary Cannot be converted to NSString.
在谷歌周围进行了一次侦察之后,我看不出这个问题的头绪

谁能给我指一下正确的方向吗

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>
  }
}
var-api={
getData(){
var url='1〕https://example.com/api/json/'
返回fetch(url).then((res)=>res.json())
}
}
类GetCategories扩展组件{
建造师(道具){
超级(道具)
此.state={
类别:[]
}
}
组件willmount(){
api.getData().then((res)=>{
这是我的国家({
类别:res
})
})  
}
render(){
var catLoop=this.state.categories.map(函数(obj,索引){
var catTitle='',
catImage='';
catTitle=对象标题;
catImage=obj.image;
返回(
{catTitle}
)
});
返回{catLoop}
}
}

这应该可以解决您的问题

<Image source={{uri: catImage}} style={{width: 400, height: 400}}>
     <Text>{catTitle}</Text>
</Image>

{catTitle}

我通过添加{catTitle}解决了这个问题,但是图像不会显示。你确定包含撇号吗?问题是您将变量包装在括号中,使其成为一个对象。删除了撇号。现在显示图像。最后一行代码是:{catTitle}感谢您的帮助!你提交这封信时,我正在起草我的答案。看来是你自己想出来的D在事先的评论中如上所述解决。无论如何,谢谢你。