當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Python编程从入门到实践~JSON
生活随笔
收集整理的這篇文章主要介紹了
Python编程从入门到实践~JSON
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
import json
#AttributeError: module ‘json’ has no attribute ‘dump’
#模塊的名字被我命名成了json.py,名稱沖突#使用json.dump()和json.load()
numbers = [2, 3, 4, 5, 66, 12]
filename = './data/number.json'
with open(filename,'w') as file:json.dump(numbers,file)with open(filename) as f:numbers = json.load(f)
print(numbers)#json.dumps() 將JSON對象轉(zhuǎn)換為JSON字符串.
filename = "./data/numbers.json"
with open(filename, "w") as f:number_string = json.dumps(numbers)f.write(number_string)#json.loads() 將JSON字符串轉(zhuǎn)換為JSON對象
with open(filename) as f:number_string = f.read()numbers = json.loads(number_string)
print(numbers)
總結(jié)
以上是生活随笔為你收集整理的Python编程从入门到实践~JSON的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle查看锁表进程,杀掉锁表进程
- 下一篇: Spring Data JPA 从入门到