convert between json and array

======make array  to json to str=======

import json
a=[1,2,3,4]
b=[5,6]
a.extend(b)
>>>a
>>>[1, 2, 3, 4, 5, 6]
!!!!a.append(b)
!!!!>>>a
!!!!>>>[1, 2, 3, 4, [5, 6]]
paws = {}
paws[‘ids’]=a
sqldata = json.JSONEncoder().encode(paws)
>>>sqldata
>>>'{“ids”: [1, 2, 3, 4, 5, 6]}’

 

=====convert str to array=====

paws = json.JSONDecoder().decode(sqldata)
>>>paws
>>>{u’ids’: [1, 2, 3, 4, 5, 6]}
>>>paws[‘ids’]
>>>[1, 2, 3, 4, 5, 6]

paws[‘latest_id’]=23123
paws[‘update_time’]=’2012-12-12 00:00:00′

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注