Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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 如何使用map函数在React.js上显示键到组件上有空格的json_Javascript_Reactjs - Fatal编程技术网

Javascript 如何使用map函数在React.js上显示键到组件上有空格的json

Javascript 如何使用map函数在React.js上显示键到组件上有空格的json,javascript,reactjs,Javascript,Reactjs,我正在尝试使用股票市场的API,所以当表单提交并收到下面的JSON文件时,我会调用API,并将其值存储在钩子上 "Meta Data": { "1. Information": "Daily Prices (open, high, low, close) and Volumes", "2. Symbol": "IBM", "3. L

我正在尝试使用股票市场的API,所以当表单提交并收到下面的JSON文件时,我会调用API,并将其值存储在钩子上

    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "IBM",
        "3. Last Refreshed": "2020-12-04",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2020-12-04": {
            "1. open": "123.9700",
            "2. high": "127.3800",
            "3. low": "123.6400",
            "4. close": "127.2000",
            "5. volume": "5522760"
        },
        "2020-12-03": {
            "1. open": "124.1600",
            "2. high": "124.8600",
            "3. low": "123.2900",
            "4. close": "123.6100",
            "5. volume": "4548161"
        }
}
所以我创建了两个简单的组件:StockList和StockItem,StockList用于呈现所有StockItem,我无法访问StockItem中JSON的值,因为我不知道如何显示键上有空格的数据。通常JSON是这样的:

  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    }
users.map((user) => {
   return(
     <p>{user.name}</p>
     <p>{user.username}</p>
   )
});
使用以下地图很容易显示:

  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    }
users.map((user) => {
   return(
     <p>{user.name}</p>
     <p>{user.username}</p>
   )
});
users.map((用户)=>{
返回(
{user.name}

{user.username}

) });

当我试图使用map来解决这个问题时,我得到了未定义的属性。

来访问键上有空格的数据

user['key'] => 

example : user['first name']
let a={“first name”:“dileep”};

log(a['first name'])
user['key']=>example:user['first name'],试试这个让我知道例如,让a={“first name”:'dileep'};a[“名字”]让我知道它是否对你有帮助