|
import json
|
|
|
|
# https://py4e-data.dr-chuck.net/comments_42.json
|
|
data = '''
|
|
{
|
|
"name" : "Chuck",
|
|
"phone" : {
|
|
"type" : "intl",
|
|
"number" : "+1 734 303 4456"
|
|
},
|
|
"email" : {
|
|
"hide" : "yes"
|
|
}
|
|
}'''
|
|
|
|
info = json.loads(data)
|
|
print('Name:', info["name"])
|
|
print('Hide:', info["email"]["hide"])
|
|
|
|
data_2 = '''
|
|
[
|
|
{ "id" : "001",
|
|
"x" : "2",
|
|
"name" : "Chuck"
|
|
} ,
|
|
{ "id" : "009",
|
|
"x" : "7",
|
|
"name" : "Brent"
|
|
}
|
|
]'''
|
|
|
|
info = json.loads(data_2)
|
|
print('\n\nUser count:', len(info))
|
|
|
|
for item in info:
|
|
print('Name', item['name'])
|
|
print('Id', item['id'])
|
|
print('Attribute', item['x'])
|