Converting string file into json format file

后端 未结 3 1097
别跟我提以往
别跟我提以往 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:28

    In this case
    You need to read the content of file

    obj, end = self.raw_decode(s, idx=_w(s, 0).end()) TypeError: expected string or buffer
    


    
        import json
    
        f = open("string.txt", 'w')
        f1 = open("stringJson.txt", 'r')
        data = json.loads(f1)
        f.write(json.dumps(data, indent=1))
        f.close()
    
    

提交回复
热议问题