python3.10中json读取问题,正常写入,读出现问题

python3.10中json读取问题,正常写入,读出现问题
# 写入代码
import json
numbers = [2, 3, 5, 7, 11, 13]
string1 = "hello world"
filename = 'numbers.json'

with open(filename, 'w') as f:
    json.dump(numbers, f)
    json.dump(string1, f)
# 读入代码
import json

file_name = 'numbers.json'

with open(file_name) as f:
    numbers = json.load(f)
   
print('1'.center(20,'-'))
print(numbers)
运行结果及报错内容
Traceback (most recent call last):
  File "/home/helmer/scripts/python3/json_read.py", line 6, in 
    numbers = json.load(f)
  File "/usr/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 21 (char 20)

在read()和write()方法中进行写入和读入操作没有问题

想要达到按顺序写入,然后按顺序读入

代码改成这样:

# 写入代码
import json

numbers = [2, 3, 5, 7, 11, 13]
string1 = "hello world"
filename = 'numbers.json'

with open(filename, 'w') as f:
    f.write(json.dumps(numbers))

# 读入代码
import json

file_name = 'numbers.json'

with open(file_name) as f:
    numbers = json.loads(f.read())

print('1'.center(20, '-'))
print(numbers)

在修改的代码中,第9行,没有把string1变量的内容写进去,如果值写入一个变量,是可以正常读取的,关键就是如何写入两种数据(列表,字符串),然后再把两种数据顺利读取出来