解码JSON对象失败:预期值:第1行第1列(字符0)< / p> [英] Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>

查看:246
本文介绍了解码JSON对象失败:预期值:第1行第1列(字符0)< / p>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有点重复,但是我找不到解决方案。
当我调用flask应用程序并传递JSON数据时,出现错误:

This question is kind of duplicate but I could not find a solution to it. When I am calling the flask app and passing the JSON data, I am getting the error:

"Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)</p>"

下面是烧瓶代码:

@app.route('/data_extraction', methods=['POST'])
def check_endpoint2():   
    data= request.json()
    result = data['title']
    out={"result": str(result)}
    return json.dumps(out)
    #return 'JSON Posted'

这就是我从卷曲中称呼它的方式

This is how I am calling it from curl

curl -i -H "Content-Type: application/json" charset=utf-8 -X POST -d '{"title":"Read a book"}' 127.0.0.1:5000/data_extraction

我也想知道如何卷曲JSON文件(test_data.json),像这样吗?

I also want to know how can I curl the JSON file(test_data.json), will it be like this?

curl -i -H "Content-Type: application/json" charset=utf-8 -X POST -d @test_data.json 127.0.0.1:5000/data_extraction


推荐答案

您几乎在那里。问题是 -d 会覆盖您提供的 Content-Type 标头。尝试使用-data 代替 -d

You're mostly there. The problem is the -d overrides the Content-Type header that you're providing. Try --data instead of -d.

并将 data = request.json()更改为 data = request.json

这篇关于解码JSON对象失败:预期值:第1行第1列(字符0)&lt; / p&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆