在这里,我用flask编写的服务器基本上就像从firebase集合中获取文档,并将该数据(整个数据)作为响应发送。我的firebase收藏有9000份文件,我想作为回复发送。这是我的密码-
def getAllCredits(db):
mainData = []
try:
collection = db.collection('Credits')
docs = collection.stream()
for index, doc in enumerate(docs):
res = doc.to_dict()
mainData.append({"id":doc.id,"data":res})
print(len(mainData))
return jsonify(mainData)
虽然我在postman中成功地将所有数据作为json获取,但在angular中,我得到了json解析错误。将响应类型设置为text是可行的,但我需要将数据设置为json(“Content-type”也设置为“application/json”)。这是我的角度代码-
getAllCredits() {
this.http.get('http://localhost:8080/getAllCredits')
.subscribe(result => {
console.log(result);
})
}
我犯了这样的错误-
"Http failure during parsing for http://localhost:8080/getAllCredits"
SyntaxError: Unexpected token e in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4400/vendor.js:37062:51
谁能告诉我哪里出了什么问题吗?在nodejs中创建相同的api工作得非常好,我得到了所有9000个angular文档(JSON解析正确)。不知道烧瓶里有什么问题。我也在正确设置内容类型。这个问题与大数据有关吗?有人能帮我解决这个问题吗?