簡體   English   中英

如何從JSON文件讀取對象URI(JSON文件)

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

我能夠讀取此JSON文件,但無法讀取對象URI JSON文件。 如何使用對象URI JSON文件?

這就是我嘗試讀取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 });
      })

  }

這是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."
      },

使用提取第一個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 });
      })

  }

我認為這只是一個普通的JSON。 您可以通過直接讀取字段urlthumnail_url來獲取文件

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

您可以通過以下方式顯示此文件

<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