注意:
1. split处理对象是字符串
2. split返回的是一个列表
3. strip处理对象是字符串
s = '{"period":"20201030","language":"zh_CN",\ "beginTime":"2020-10-01","endTime":"2020-10-30"}' # split()方法以参数字符串为分割符 ,将字符串切割为多个字符串,作为元素存入一个列表,并返回这个列表。 s1 = s.split(",") print(type(s1)) # split返回的是一个列表 for i in s1: if i.startswith("{"): print("{\n" + i.lstrip('{') + ",") elif i.endswith("}"): print(i.rstrip('}') + "\n}") else: print(i + ",") 结果如下 : <class 'list'> { "period":"20201030", "language":"zh_CN", "beginTime":"2020-10-01", "endTime":"2020-10-30" }