json數據

json數據:html

01json數據python

json 文件組成:
             {}   表明對象(字典)

             []  表明列表

              :  鍵值對

              , 分隔兩部分


import json


 jsonStr=`{"name":"張三","age":18,
 "hobby愛好":["money","power","english"],"params":{
 "a":1,"b":2}}`

# 將json格式的字符轉換成python數據類型對象

jsonData=json.loads(jsonStr)
print(jsonData)

print(type(jsonData))


http://localhost:8088/index.html

02json數據json

import json

jsonStr=`{"name":"張三","age":18,
 "hobby":["money","power","english"],"params":{
 "a":1,"b":2}}`

# 將json格式的字符轉換成python數據類型對象
jsonData=json.loads(jsonStr)
print(jsonData)
print(type(jsonData))



# 將python 數據類型的對象轉換成json 格式字符、
jsonDATA2={"name":"張三","age":18}
jsonStr2=json.dumps(jsonDATA2)
print(jsonStr2)

03讀本地json網絡

import json


# 讀取本地json
# 
path1=r"E:\Studypython\網絡爬蟲\json\1\1.json"

with open(path1,"rb") as f:

     data=json.load(f)

     print(data)

 04寫本地jsongoogle

import json

#寫入本地json
path1=r"E:\Studypython\網絡爬蟲\json\1\2.json"
aa={
"sites": [
{ "name":"菜鳥教程" , "url":"www.runoob.com" }, 
{ "name":"google" , "url":"www.google.com" }, 
{ "name":"微博" , "url":"www.weibo.com" }
]
}
with open (path1,"w") as f:
    json.dump(aa,f)

 05json數據url

json 文件組成:
             {}   表明對象(字典)

             []  表明列表

              :  鍵值對

              , 分隔兩部分


import json


 jsonStr=`{"name":"張三","age":18,
 "hobby愛好":["money","power","english"],"params":{
 "a":1,"b":2}}`



# 將json格式的字符轉換成python數據類型對象

jsonData=json.loads(jsonStr)
print(jsonData)

print(type(jsonData))
{
"sites": [
{ "name":"菜鳥教程" , "url":"www.runoob.com" }, 
{ "name":"google" , "url":"www.google.com" }, 
{ "name":"微博" , "url":"www.weibo.com" }
]
}

 

{"sites": [{"name": "\u83dc\u9e1f\u6559\u7a0b", "url": "www.runoob.com"}, {"name": "google", "url": "www.google.com"}, {"name": "\u5fae\u535a", "url": "www.weibo.com"}]}
相關文章
相關標籤/搜索