python post接口接收json数据或数组
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
1:接收json数据
# post XML 输入格式 {"bl_code": "BLA123P013", "ua_code": "UAA123P008"}
@app.route('/mes/api/v1.0/postxml', methods=['POST', 'OPTIONS', 'GET'])
def comm_postxml():
# bl_code 和 ua_code 允许用户自行输入,用户传入 bl_code和ua_code值
searchlists = request.get_json()
print(searchlists)
bl_code = searchlists['bl_code']
ua_code = searchlists['ua_code']
print(bl_code, ua_code)
输出如下
{'bl_code': 'BLA123P014', 'ua_code': 'UAA123P014'}
BLA123P014 UAA123P014
或者换一种写法
@app.route('/mes/api/v1.0/cell', methods=['POST'])
def create_cell():
# -----从request.json中取相应的字段
if not request.json or not 'moduleid' in request.json:
abort(400)
if not request.json or not 'cellid' in request.json:
abort(400)
moduleid = request.json['moduleid']
cellid = request.json['cellid']
2:接收list数据,并以list json输出
@app.route('/mes/api/v1.0/get_dpcapacklists', methods=['POST', 'OPTIONS', 'GET'])
def get__dpcapacklists():
print(request)
print("print serarchlists")
packageList = request.get_json()
print(packageList)
print(packageList[0])
print(packageList[0]["moduleList"])
print(len(packageList[0]["moduleList"]))
print(packageList[0]["moduleList"][0])
print("=====================================")
print(packageList[0]["moduleList"][0]['moduleCode'])
print("=====================================")
print(packageList[0]["moduleList"][0]["cellList"])
print("=====================================")
print(packageList[0]["moduleList"][0]["cellList"][0])
return jsonify({'list': packageList})
或者只返回部分字段作为list
@app.route('/mes/api/v1.0/get_dpcapacknums', methods=['POST', 'OPTIONS', 'GET'])
def get_dpcapacknums():
print("======================getccccccccccccccccccccccccccccccccccccccccapsapacklist post")
print(request)
print("print serarchlists")
packageList = request.get_json()
print(len(packageList))
packlist = []
i = 0
for i in range(len(packageList)):
print(packageList[i]['global_pack_code'])
packlist.append(packageList[i]['global_pack_code'])
return jsonify({'list': packlist})#返回pack号码
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
4 个月前
8c391e04
6 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)