当前位置 : 主页 > 编程语言 > python >

Python之json

来源:互联网 收集:自由互联 发布时间:2022-07-17
加载本地json: with open('./test.json', 'r') as f: data = json.load(f) 删除json中一个元素# -*- coding=utf8 -*- import io import urllib2 from urllib2 import urlopen from PIL import Image import json if __name__ == '__main__': wit

加载本地json:

with open('./test.json', 'r') as f:
data = json.load(f)


删除json中一个元素# -*- coding=utf8 -*-
import io
import urllib2
from urllib2 import urlopen
from PIL import Image
import json


if __name__ == '__main__':
with open('j', 'r') as f:
data = json.load(f)

ll = data['list']
for user in ll:
if user['url'] == '5348728':
print 'find it!'
ll.remove(user)


for user in data['list']:
if user['url'] == '5348728':
print 'find it!'

with open('j', 'w') as f:
f.write(json.dumps(data))

 

黄世宇/Shiyu Huang's Personal Page:​​https://huangshiyu13.github.io/​​



上一篇:Python之多进程
下一篇:没有了
网友评论