【发布时间】:2021-08-02 07:20:18
【问题描述】:
我有下面发布的 json 响应。如下 json 部分所示,parametersobject 在这一行中发出(这是一个角度应用程序)
this._FromInsToSiteDataService.emitOnSubmitButtonClikedBroadcast(parameters)
它被接收到
this.subscriptionBroadcastEmitterOnSubmitButtonClicked = this._FromInsecticidesToSiteMapDataService.getBroascastEmitterOnSubmitButtonClicked().subscribe((response:Object)=>{
response['siteGeometry'] = this.selectedSite.geometry
console.log("response: ", response)
this.sSProvider.startWebServiceFor(response)
});
在后面的代码中,我想将 json 格式的响应传递给 web 服务并接收它,如 websrvicepostedbelow 中所示`
当我运行代码时,我希望看到 json 对象的内容
{
"dist1": d1,
"dist2": d2,
"date1": date1,
"date2": date2,
"ingredient": activeIngredient
}
但我得到NONE
请告诉我如何正确地从 web 服务获取 json 对象
json
private submit() {
let parameters = {
"dist1": d1,
"dist2": d2,
"date1": date1,
"date2": date2,
"ingredient": activeIngredient
}
this._FromInsToSiteDataService.emitOnSubmitButtonClikedBroadcast(parameters)
接收 json 对象
this.subscriptionBroadcastEmitterOnSubmitButtonClicked = this._FromInsecticidesToSiteMapDataService.getBroascastEmitterOnSubmitButtonClicked().subscribe((response:Object)=>{
response['siteGeometry'] = this.selectedSite.geometry
console.log("response: ", response)
this.sSProvider.startWebServiceFor(response)
});
网络服务:
@app.route("/insSpecifications/<parameters>", methods=['GET'] )
def insSpecifications(parameters):
# print(request.json())
print(request.get_json())//returns NONE
return "OK"
【问题讨论】:
-
@Chillie this.sSProvider.startWebServiceFor(response) 启动网络服务
-
你可能想用合适的标签修改你的标签,让正确的人看到这个问题,因为这个问题是一个较少的烧瓶、python 问题和更多的 JS
-
你测试过邮递员的 Flask 路由并打印了 json 吗?请注意,如果您没有在标头中将
content-type设置为application/json,get_json()将返回 null 并且您正在发出 GET 请求,get_json()会读取post或put请求的正文 -
@shoaib30 你能提供一个代码示例吗?如何设置内容类型??
-
我会放弃它作为答案