Parse data from JSON in ReactJS

后端 未结 1 1666
自闭症患者
自闭症患者 2021-02-01 18:48

I have data like this:

{
  \"movies\": [
    {
      \"abridged_cast\": [
        {
          \"characters\": [
            \"Dominic Toretto\"
          ],
             


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 19:25

    React lives in JavaScript. So parsing a JSON string is done with:

    var myObject = JSON.parse(myjsonstring);
    

    How to fetch a file from somewhere with AJAX is a different question.

    You could use fetch() for this. See for example
    https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API or
    https://davidwalsh.name/fetch or
    https://blog.gospodarets.com/fetch_in_action

    0 讨论(0)
提交回复
热议问题