当它是JSON节点名称的一部分时,如何处理“:"? [英] How do you treat ':' when it's part of a JSON node name?

查看:182
本文介绍了当它是JSON节点名称的一部分时,如何处理“:"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看我的wordpress网站上的JSON输出,并且正在尝试将帖子的精选图片拖到我的应用中.但是,我在一个节点名称中遇到了一个':'问题.

I am looking at a JSON output from my wordpress site, and I'm trying to pull in the featured image of the post to my app. However, I've run into a little problem with a ':' in one of the node names.

节点名称为'wp:featuredmedia',我正在尝试提取位于其下的href.

the node name is 'wp:featuredmedia' and I'm trying to pull in the href that's sitting under it.

在我的本机代码中,我有:

in my react native code, I have:

      <Image
          source={item.wp:featuredmedia.href}
          />

有什么办法解决这个问题吗?

Any ideas how to resolve this ?

render() {
return (
  <View style={styles.theContainer}>
    <Text style={styles.topicTitle}>MY POSTS</Text>
    <FlatList
    data={this.state.data}
    keyExtractor={this.state.data.id}
    renderItem={({item}) =>
      <View>
            <Image source={item['wp:featuredmedia'].href} />
             // the line above throws an error stating that it's 
             // not an object. Further that it's undefined. 
            <HTMLView
              value={item.title.rendered}
              styles={styles.topicTitle}
            />
            <HTMLView
              value={item.excerpt.rendered}
            />
      </View>
    }
    />
  </View>
);
}

推荐答案

如果它是JSON对象,则可以这样访问它,而不是item["wp:featuredmedia"].href

If it's a JSON object, you can access it like this instead item["wp:featuredmedia"].href

这篇关于当它是JSON节点名称的一部分时,如何处理“:"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆