Regex:
\s*\]\s*$
移除第一个json字符串中的结尾]和第二个json字符串中的[,并在中间添加一个,以使用regex和字符串替换来连接列表。
data1 = """[
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
data2 = """
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
import json, re
result = re.sub(r"\s*\]\s*$",",",data1) + re.sub(r"^\s*\[\s*","",data2)
print(result)
#make sure it's valid json:
json.loads(result)
反序列化。 将这两个列表相加。 重新序列化。
data1 = """[
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
data2 = """
"key1":"value1",
"key2":12563
"key1":"value1",
"key2":12563
import json