我想在POST请求中将对象数组存储到Session我收到以下错误:
预期字符串,dict发现
def POST(self):
deviceArr1=[{"id":"01","name":"abc"},{"id":"02","name":"abcd"}]
for device in deviceArr1:
cherrypy.session['deviceArr'].append(device)
return cherrypy.session['deviceArr']
另外,我想检查是否存在重复的对象。
答案 0 :(得分:0)
您可以在for:
中尝试此代码try:
cherrypy.session['deviceArr'].append(device)
except:
cherrypy.session['deviceArr'] = [device]