json

http://stackoverflow.com/questions/23600578/python-sql-alchemy-how-to-jsonify-a-class-object-result-from-a-database-query

使用vars()轉換object-> dictionary

由於使用SQLAlchemy 會產生 _sa_instance_state

字串轉字典 route_json = vars(route) 移除_sa_instance_state route_json.pop("_sa_instance_state", None)

import json
h = '{"foo":"bar", "foo2":"bar2"}'
type(h)
<type 'str'>
d = json.loads(h)
d
{u'foo': u'bar', u'foo2': u'bar2'}
type(d)
<type 'dict'>

results matching ""

    No results matching ""