functionsex.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:ublock-antiskimming-list 作者: byaka 项目源码 文件源码
def json2generator(data, arrayKey=None):
   """
   ??????? ???????????? ?????????? json ? ?????????. ??? ????????? ???????? ?????? ?????? ?? ???????? ??????? ??????. ????? ?????? ????????? ?????? ??? ??????? (??????? ????? ??????????? ? ?????????). arrayKey ?????? ????????? ?? ??????, ????? ???? ???????? (key1.key2)
   """
   from ijson import common
   # from io import BytesIO
   from cStringIO import StringIO
   #! yajl2 ??????? ???????? ??????????? ???????, ?? ?? ?????? ?????? ??? ? ?? ??????? ??? ??????????, ????? "Yajl shared object cannot be found"
   try: import ijson.backends.yajl2_cffi as ijson
   except:
      try: from ijson.backends import yajl2 as ijson
      except:
         try: from ijson.backends import yajl as ijson
         except: from ijson.backends import python as ijson
   try: f=StringIO(data)
   except: f=StringIO(data.encode('utf-8'))
   def _fixJSON(event):
      # ??????? ?????????? "????" ?????????, ??????? ???????? ??? ???????? ???? ???????? ? decimal()
      if event[1]=='number':
         return (event[0], event[1], float(event[2]) if math.modf(event[2])[0] else int(event[2]))
      else: return event
   events=imap(_fixJSON, ijson.parse(f))
   g=common.items(events, (arrayKey+'.item' if arrayKey else 'item'))
   # g=ijson.items(f, (arrayKey+'.item' if arrayKey else 'item'))
   return g
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号