0
這是我的代碼:REST風格瓶解析JSON陣列,parse_args()
parser = reqparse.RequestParser(bundle_errors=True)
parser.add_argument('list', type=list, location="json")
class Example(Resource):
def post(self):
#json_data = request.get_json(force=True)
json_data = parser.parse_args()
return json_data
如果我發佈一個JSON對象是這樣的:
{
"list" : ["ele1", "ele2", "ele3"]
}
parser.parse_args()
它解析到這條巨蟒列表:
'list': ['e','l','e','1']
request.get_json()
的作品,但我真的很想有驗證的reqparser ... 如何才能讓parser.parse_args()
與JSON數組一起正常工作?
(我得到這個錯誤:TypeError("'int' object is not iterable",) is not JSON serializable
,如果如果JSON數組包含整數:'list': [1, 2, 3]
)