json.loads 不支持带注释的json格式, 把文件内容读取出来删掉注释再加载
def parse_json_str(jsonStr: str):
pos = 0
bPos = 0
flg = '/'
isMathModel = False
while (True):
pos = jsonStr.find(flg, pos)
if pos > -1:
if isMathModel:
jsonStr = jsonStr[:bPos - 1] + jsonStr[pos + len(flg):]
pos = bPos
isMathModel = False
flg = '/'
continue
lineBeginPos = jsonStr.rfind('\n', 0, pos)
lineStr = jsonStr[lineBeginPos:pos]
num = len(re.findall('"', lineStr))
if num % 2 == 0:
if jsonStr[pos + 1] == '*':
flg = '*/'
isMathModel = True
bPos = pos
continue
elif jsonStr[pos + 1] == "/":
lineEndpos = jsonStr.find('\n', pos)
jsonStr = jsonStr[:pos - 1] + jsonStr[lineEndpos - 1:]
continue
pos = pos + 1
else:
break
return jsonStr