Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

您好,生成的json文件里面似乎格式有点问题, #3

Open
brave-ciao opened this issue Oct 17, 2023 · 1 comment
Open

Comments

@brave-ciao
Copy link

brave-ciao commented Oct 17, 2023

比如:
.....
]
} (这里报错了,两个图片间)
{
"1": [
{
"000001": [
[

似乎不符合json的格式,缺少逗号之类的?请问如何解决呢?谢谢!

训练运作报错: raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1025 column 1 (char 23857)

@Reverie5
Copy link
Collaborator

import json
import re
char_at_position = []
for i in range(36):
    with open('./seg_result/result/'+str(i)+'.json') as file:
        content = file.read()
        pattern = r'\}(\r?\n)\{'
        content = re.sub(pattern,'};\n{',content)
        dictionaries = content.split(';')
    i= 0
    for dictionary in dictionaries:
        data = json.loads(dictionary)
        i = i+1
        print(list(data.keys())[0])
        with open('./seg_result/result/list.json', 'a') as file:
                json.dump(data, file, indent=4, sort_keys=True)
                file.write('\n')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants