python&json-如何向对象添加对象

时间:2018-08-09 00:56:31

标签: python json

{"something": {}}

如何在“某物”内添加另一个对象

{"something": {"something2": "as"}}

我尝试了append()update(),但是这些都不起作用。我还想添加尽可能多的数组和对象

1 个答案:

答案 0 :(得分:0)

使用from flask import Flask, render_template, request, jsonify import aiml import os app = Flask(__name__) @app.route("/") def hello(): return render_template('chat.html') @app.route("/ask", methods=['POST']) def ask(): message = request.form['messageText'].encode('utf-8').strip() kernel = aiml.Kernel() if os.path.isfile("bot_brain.brn"): kernel.bootstrap(brainFile = "bot_brain.brn") else: kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b") kernel.saveBrain("bot_brain.brn") # kernel now ready for use while True: if message == "quit": exit() elif message == "save": kernel.saveBrain("bot_brain.brn") else: bot_response = kernel.respond(message) # print bot_response return jsonify({'status':'OK','answer':bot_response}) if __name__ == "__main__": app.run(host='0.0.0.0', debug=True) 来完成任务:

pip install jq