init
This commit is contained in:
31
BaseModels/json_funcs.py
Normal file
31
BaseModels/json_funcs.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
|
||||
|
||||
def del_from_txt_bad_json_symbols(txt):
|
||||
|
||||
log = ''
|
||||
error = True
|
||||
while error and len(txt) > 0:
|
||||
try:
|
||||
json.loads(txt)
|
||||
error = None
|
||||
except json.JSONDecodeError as e:
|
||||
msg = '- длина контента = {2} - {1} - удален символ {0}'.format(
|
||||
txt[e.pos],
|
||||
str(e),
|
||||
str(len(txt)-1)
|
||||
)
|
||||
log = '{0}<br>{1}'.format(log, msg)
|
||||
print(msg)
|
||||
txt = txt[:e.pos] + txt[e.pos+1:]
|
||||
error = e
|
||||
|
||||
# import re
|
||||
# r_str = r'[{\[]([,:{}\[\]0-9.\-+A-zr-u \n\r\t]|".*:?")+[}\]]'
|
||||
# pattern = re.compile(r_str)
|
||||
# txt = re.sub(r_str, '',txt)
|
||||
# res = pattern.search(txt)
|
||||
# if res:
|
||||
# txt = res.string
|
||||
|
||||
return txt, log
|
||||
Reference in New Issue
Block a user