-2
我在寫一個使用Flask的小應用程序。我的服務器代碼如下:TypeError:未定義不是JSON可序列化
@app.route('/loadNext')
def loadNext():
tmp = "Okay"
return render_template("next.html",message = {"date_to":"from","date_from":tmp,"error_stat":[30,400,21,45],"mac_length":[7,7,7,7],"mac":[["1.1.1.1","1.2.1.2","3.2.1.1","3.1.4.5","1.3.2.4","5.5.4.3","2.1.6.7"], ["6.1.1.1","1.2.3.2","3.2.1.1","3.2.4.5","1.3.2.4","5.5.4.3","2.1.6.7"], ["9.1.1.1","4.2.1.2","3.2.1.1","3.7.4.5","1.3.2.4","5.5.4.3","2.1.6.7"], ["10.1.1.1","1.2.1.2","3.2.1.1","3.6.4.5","1.3.2.4","5.5.4.3","2.8.6.7"]]})
在我的javascript代碼,我使用一個for循環和訪問值如下:
$("#loadtable").ready(function(){
alert("Inside function");
for (i = 0; i < 7; i++) {
var tmp = {{message.mac[0][i]|tojson|safe}};
alert(tmp);
}
});
但我收到此錯誤:
TypeError: Undefined is not JSON serializable
我想我不應該在這裏使用循環變量。但是它的解決方案是什麼?我哪裏錯了?
你還在使用'var tmp = {{message.mac [0] [i]}};'?此問題已在[上一個問題]中解決(http://stackoverflow.com/questions/33344773/unexpected-number-error-javascript)。 –
@RoryMcCrossan不,我改變了代碼。但它仍然不起作用。 – sklearning