编程语言
首页 > 编程语言> > python flask接收json字符串

python flask接收json字符串

作者:互联网

前端

var mydata={
                            environmentnameselect:$("#environmentname").val()
                           ,systermnameselect:$("#systermname").val()
                           ,jsonobj:JSON.parse($("#jsonstr").val())
                        };

              $.ajax({
                        type :"POST"
                        ,url: '/sysconfig_save_jsonstr'
                        ,data: JSON.stringify(mydata)
                        ,dataType: 'text'
                        ,success: function (data) {
                                alert(data);
                        }
                      });

后端

@app.route('/sysconfig_save_jsonstr', methods=['GET','POST'])
@wrapper
def sysconfig_save_jsonstr():
    try:
        data = request.get_data()
        data = json.loads(data)
        environmentname = data['environmentnameselect']
        systermname = data['systermnameselect']
        json_value =data['jsonobj']

        return "success"
    except Exception as e:
        return "error"

标签:jsonstr,val,python,sysconfig,flask,json,save,data
来源: https://blog.csdn.net/peacezhi/article/details/123060848