python 解析json

python 解析json


Simplejson 是一个可以将字符或者文件解析成json的python库,能够将python的字典和列表解析成一个json字符.python

咱们指定下面的字符为json的数据c++

json_string='{"姓":"wen","名":"昌寿"}'json

咱们经过下面的方式进行解析spa

import simplejson as json
parsed_json=json.loads(json_string)code

经过上面的操做咱们能够经过普通的字典的方式进行访问对象

print(parsed_json['姓名'])
"wen"unicode

你也能够经过下面的方式将一个dict转换成json对象string

 d={'first_name':'wen',it

  'second_name':'changshou',table

  title':['python','c++'],

  }

print(json.dumps(d))

{"title": ["python", "c++"], "first_name": "wen", "second_name": "changshou"}

JSON Python 2 Python 3
object dict dict
array list list
string unicode str
number (int) int, long int
number (real) float float
true True True
false False False
null
相关文章
相关标签/搜索