我正在设置一个文件,以便可以为数据库添加种子。我想从外部api获取数据,然后映射返回的数据并相应地进行种子设置。我正在使用创建的脚本(仅是node)运行文件。当我从客户端和Postman上从API提取数据时,都得到了预期的结果。但是,当我尝试使用正在创建的种子文件进行尝试时,数据看起来与我应该获得的内容完全一样,除了response.data现在是字符串而不是对象。我似乎不知道为什么会这样。
从种子文件返回的数据
data: '{"columns":[{"code":"Region","text":"region","type":"d"},{"code":"Kon","text":"sex","type":"d"},{"code":"Tid","text":"year","type":"t"},{"code":"BE0101N1","text":"Population","comment":"The ' +
'tables show the conditions on December 31st for each respective year ' +
'according to administrative subdivisions of January 1st of the ' +
'following year\\r\\n","type":"c"},{"code":"BE0101N2","text":"Population ' +
'growth","comment":"Population growth is defined as the difference ' +
'between the population at the beginning of the year and at the end of ' +
'the ' +
'year.\\r\\n","type":"c"}],"comments":[],"data":[{"key":["0117","1","2013"],"values":["20389","154"]},{"key":["0117","2","2013"],"values":["20106","72"]}]}'
数据返回邮递员
{
"columns": [
{
"code": "Kon",
"text": "sex",
"type": "d"
},
{
"code": "Tid",
"text": "year",
"type": "t"
},
{
"code": "BE0101N1",
"text": "Population",
"comment": "The tables show the conditions on December 31st for each respective year according to administrative subdivisions of January 1st of the following year\r\n",
"type": "c"
},
{
"code": "BE0101N2",
"text": "Population growth",
"comment": "Population growth is defined as the difference between the population at the beginning of the year and at the end of the year.\r\n",
"type": "c"
}
],
"comments": [],
"data": [
{
"key": [
"1",
"2013"
],
"values": [
"4814357",
"48452"
]
},
{
"key": [
"2",
"2013"
],
"values": [
"4830507",
"40519"
]
}
]
}