[英]Error: How to serialize data from getStaticProps in Next.js
I am trying to fetch data from an Api but for sorry i've received this Error:我正在尝试从 Api 获取数据,但很抱歉我收到了此错误:
Server Error Error: Error serializing .results
returned from getServerSideProps
in "/".服务器错误错误:序列化从“/”中的
getServerSideProps
返回的.results
时出错。 Reason: undefined
cannot be serialized as JSON.原因:
undefined
不能序列化为JSON。 Please use null
or omit this value.请使用
null
或省略此值。
The props you're passing contain an object with a key of value undefined
.您传递的道具包含一个 object ,其键值为
undefined
。 A quick solution would be一个快速的解决方案是
return {
props: {
results: JSON.parse(JSON.stringify(request.results));
}
}
JSON.stringify
will remove those undefined values. JSON.stringify
将删除那些未定义的值。 You can try it out in your browser console: JSON.stringify({someKey:undefined})
您可以在浏览器控制台中试用:
JSON.stringify({someKey:undefined})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.