我有一个烧瓶应用程序,它从 jsonify 函数返回输出,但显示在 html 上的输出并不漂亮。我现在解析这个输出并在将其返回到 html 之前对其进行修改。我试图迭代 json 输出,但它不允许我这样做。我怎么做?
首先是我网页上 jsonify 函数的输出
预测:苹果雪松锈,99.6459424495697,Bell_Pepper 健康,0.2868120325729251,蓝莓健康,0.05757397739216685
我想要这样的东西
预测:
苹果雪松锈病:99.6459424495697
Bell_Pepper 健康:0.2868120325729251
蓝莓健康:0.05757397739216685
现在这是我的 app.py 文件中相同的代码
@app.route('/predict', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
# Get the file from post request
f = request.files['file']
# Save the file to ./uploads
basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'uploads', secure_filename(f.filename))
f.save(file_path)
result = model_predict(file_path, model)
return jsonify(result)
return None
最后是我的 main.js 文件的代码
$.ajax({
type: 'POST',
url: '/predict',
data: form_data,
contentType: false,
cache: false,
processData: false,
async: true,
success: function (data) {
// Get and display the result
$('.loader').hide();
$('#result').fadeIn(600);
$('#result').text(' Prediction: ' + data);
console.log('Success!');
},
});