Converting string file into json format file

后端 未结 3 1099
别跟我提以往
别跟我提以往 2021-02-04 20:22

Ok , let say that I have a string text file named \"string.txt\" , and I want to convert it into a json text file. What I suppose to do? I have tried to use \'json.loads()\' ,bu

3条回答
  •  情深已故
    2021-02-04 20:53

    import json
    with open("string.txt", "rb") as fin:
        content = json.load(fin)
    with open("stringJson.txt", "wb") as fout:
        json.dump(content, fout, indent=1)
    

    See http://docs.python.org/2/library/json.html#basic-usage

提交回复
热议问题