Python Json解析器

Python Json解析器,第1张

Python Json解析器

这是使用json.JSONDeprer.raw_depre的
变通方法
。我希望有人提出一种更好的方法来处理此问题。

import jsonimport renonspace = re.compile(r'S')def iterparse(j):    deprer = json.JSonDeprer()    pos = 0    while True:        matched = nonspace.search(j, pos)        if not matched: break        pos = matched.start()        depred, pos = deprer.raw_depre(j, pos)        yield depred

用法示例

>>> j = '''... { "id": 1 }... { "id": 2 }... '''>>> list(iterparse(j))[{u'id': 1}, {u'id': 2}]


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5668270.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存