Python之json

加载本地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))

 

posted @ 2016-12-31 20:08  Shiyu_Huang  阅读(179)  评论(0编辑  收藏  举报