由于JSON中,标准语法中,不支持单引号,属性或者属性值,都必须是双引号括起来的

import json
content = open("123.txt").read()
print(content)
content = content.replace("'", '"') #替换单引号为双引号
print(content)
print(type(content))
datas = json.loads(content)
print(type(datas))
print(datas)
videoids = []
liveids = []
projectids = []
articleids = []
for d in datas:
    if d['type'] == 'LIVE':
        liveids.append(d["id"])
    if d['type'] == 'PROJECT':
        projectids.append(d['id'])
    if d['type'] == 'INFORMATION':
        articleids.append(d['id'])
    if d['type'] == 'VIDEO':
        videoids.append(d['id'])


print("---------------------------videoids-------------------------")
print(videoids)
print("---------------------------liveids-------------------------")
print(liveids)
print("---------------------------projectids-------------------------")
print(projectids)
print("---------------------------articleids-------------------------")
print(articleids)

 

posted on 2022-08-23 17:06  大话人生  阅读(122)  评论(0)    收藏  举报