Javascript 读取[Object:null prototype]对象会在位置0处抛出`SyntaxError:JSON中意外的令牌u`错误

Javascript 读取[Object:null prototype]对象会在位置0处抛出`SyntaxError:JSON中意外的令牌u`错误,javascript,prisma,Javascript,Prisma,因此,我试图读取对象的count属性,该属性返回为: const PAGINATION_QUERY = gql` query PAGINATION_QUERY { itemsConnection { aggregate { count } } } `; const temp = readField('itemsConnection'); temp = [Object: null prototype] { __typename

因此,我试图读取对象的
count
属性,该属性返回为:

const PAGINATION_QUERY = gql`
  query PAGINATION_QUERY {
    itemsConnection {
      aggregate {
        count
      }
    }
  }
`;

const temp = readField('itemsConnection');

temp = [Object: null prototype] {
  __typename: 'ItemConnection',
  aggregate:
   [Object: null prototype] { __typename: 'AggregateItem', count: 3 } }
当我尝试这样做时:

const a = JSON.parse(JSON.stringify(temp));
console.log(a);
我收到上面提到的错误消息,
SyntaxError:JSON中的意外标记u位于位置0


如何解决此问题?

位置0处JSON中意外的标记u
是一个很好的指示器,表明您尝试了
JSON.parse(“未定义”)
。这意味着
temp
必须是未定义的


最有可能的情况是,
readField
函数不返回值或需要回调。让函数返回一个正确的值,你就不会得到这个错误。

你能展示一下你是如何得到这个对象和JSON.stringify()的输出的吗?
JSON.parse(JSON.stringify(anything))
几乎从来都不是一件合理的事情。不是绝对没有,但几乎没有。我尝试使用
对象复制您的问题。create(null)
,我得到
“{\”\uuuu typename\:“ItemConnection\”,“aggregate\”:{\“\uu typename\”:“ItemConnection\”,“count\”:3}“
?而且似乎
对象。count
将是正确的答案,因为这就是访问对象属性值的方式。@SebastianSpeitel我已经更新了我的原始帖子,以显示对象的来源。