简体   繁体   English

如何从JSON文件读取对象URI(JSON文件)

[英]How to read object URI (JSON file) from JSON file

I am able to read this JSON file but I am not able to read object URI JSON file. 我能够读取此JSON文件,但无法读取对象URI JSON文件。 How can I use Object URI JSON File? 如何使用对象URI JSON文件?

And this is the way I tried to read Uri JSON object 这就是我尝试读取Uri JSON对象的方式

 componentDidMount(){
    const { match: { params } } = this.props;

      axios.get(params.uri).then((res)=>{
        const question = res.data[0]['uri'];
        console.log(question);
        this.setState({ question });
      })

  }

This is JSON file where Object URI contains a JSON file so how to read 这是JSON文件,其中对象URI包含JSON文件,因此如何读取

 [
          {
              "id": 59413,
              "thumbnail": {
              "id": "60255",
              "title": "dornoch-castle-whisky-bar",
              "alt": "dornoch-castle-whisky-bar",
              "url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",
              "courtesy": "",
              "position": "center"
           },
              "thumbnail_url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",
              "slug": "dornoch-castle-scotland-whisky",
              "uri": "http://trivago-magazine-work-sample-server.s3-website.eu-central-1.amazonaws.com/dornoch-castle-scotland-whisky.json",
              "title": "Dornoch Castle: A Whisky Tasting at One of the World's Most Popular Hotel Bars",
              "card_title": "Whisky Tasting at Dornoch Castle in the Scottish Highlands",
              "show_publish_date": false,
              "date": "January 29th, 2019",
              "newsletter_popup": false,
              "newsletter_popup_header_image": false,
              "taxonomies": {
              "destinations": [
            {
              "name": "Europe",
              "uri": "/destination/international/europe",
              "slug": "europe",
              "term_id": 1384
            }
          ],
          "themes": [],
          "types": [
            {
              "name": "Nature",
              "uri": "/type/nature",
              "slug": "nature",
              "term_id": 1380
            }
          ]
        },
        "excerpt": "Dornoch Castle has amassed a whisky collection unlike most any other in the world. trivago Magazine Editor, Joe Baur, signs up for their whisky tasting. Video below."
      },

Using the same way you extracted the first uri json data, fire another request to get the data from the second uri = res.data[0]['uri'] 使用提取第一个uri json数据的相同方法,触发另一个请求以从第二个uri = res.data[0]['uri']

 componentDidMount(){
    const { match: { params } } = this.props;

      axios.get(params.uri).then((res)=>{
        const question = res.data[0]['uri'];
        axios.get(question).then((qRes) => {
          console.log(qRes); //will return the data from the second uri
        })
        console.log(question);
        this.setState({ question });
      })

  }

I think this is just a normal JSON. 我认为这只是一个普通的JSON。 You can get the file by reading direct to field url and thumnail_url 您可以通过直接读取字段urlthumnail_url来获取文件

"url": "https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg",

You can show this file by 您可以通过以下方式显示此文件

<img src="https://media-magazine.trivago.com/wp-content/uploads/2019/01/23144800/dornoch-castle-whisky-bar.jpg" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM