json_preprocess.py 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import codecs
  2. import re
  3. import json
  4. fw=codecs.open('c:/tmp/result.json','w','utf-8')
  5. content=""
  6. fr=codecs.open('c:/tmp/ot.json','r','utf-8')
  7. lines=fr.readlines()
  8. for l in lines:
  9. newl=l.replace('\\"','"')
  10. content+=newl
  11. result=re.search(r'\[\["',content)
  12. content_begin=result.start()
  13. result=re.search(r'\]\]"',content)
  14. content_end=result.end()
  15. #print(result.span(1))
  16. #print(result.span(2))
  17. #for r in result:
  18. # print(r)
  19. #r=result[0]
  20. #print(r)
  21. #print(result)
  22. fw.write(content[content_begin:content_end-1])
  23. fw.close()
  24. jscontent=content[content_begin:content_end-1]
  25. jsobj=json.loads(jscontent)
  26. print()
  27. for x in jsobj[0][1][1:]:
  28. # print(x[14][0])
  29. print(x[14][11])
  30. print(x[14][10])
  31. print(x[14][2])
  32. print(x[14][78])
  33. # cnt=0
  34. # for xx in x[14]:
  35. # cnt+=1
  36. # if 'ChIJ' in str(xx):
  37. # print(xx)
  38. # print(cnt)
  39. # print(x[14][9])
  40. # try:
  41. # print(x[14][4][3])
  42. # except:
  43. # print(x[14][4])