相关疑难解决方法(0)

如何在Flask中获得POST的json?

我正在尝试使用Flask构建一个简单的API,我现在想要阅读一些POSTed JSON.我使用PostMan Chrome扩展程序发布帖子,而JSON我的帖子很简单{"text":"lalala"}.我尝试使用以下方法读取JSON:

@app.route('/api/add_message/<uuid>', methods=['GET', 'POST'])
def add_message(uuid):
    content = request.json
    print content
    return uuid
Run Code Online (Sandbox Code Playgroud)

在浏览器上它正确地返回我放入GET的uuid,但是在控制台上,它只是打印出来None(我希望它打印出来{"text":"lalala"}.有人知道我如何从Flask方法中获取发布的JSON吗?

python post json flask

284
推荐指数
8
解决办法
37万
查看次数

jQuery发布JSON

更新:我想传递var value给服务器

你好,同样老,同样老...... :)

我有一个名为的表单<form id="testForm" action="javascript:test()">和一个名为的代码区域<code id="testArea"></code>

我正在使用此代码在代码区域中字符串化并显示数据:

var formData = form2object('testForm');
document.getElementById('testArea').innerHTML = JSON.stringify(formData, null, '\t');
var value = JSON.stringify(formData, null, '\t');
Run Code Online (Sandbox Code Playgroud)

我想要的是将此数据发送到JSON文件.我一直在研究这个项目:http://ridegrab.com/profile_old/如果按下Submit Query按钮,你会看到页面的头部填充.

另外我想用这段脚本发送数据:

    function authenticate(userName, password) {
    $.ajax
    ({
        type: "POST",
        //the url where you want to sent the userName and password to
        url: 'username:password@link to the server/update',
        dataType: 'json',
        async: false,
        //json object to sent to the authentication url
        data: '{"userName": "' + userName …
Run Code Online (Sandbox Code Playgroud)

jquery post json

178
推荐指数
2
解决办法
35万
查看次数

标签 统计

json ×2

post ×2

flask ×1

jquery ×1

python ×1