您得到的字符串不是 JSON(如前所述),但部分可以解释为 JSON(= 语句的右侧部分)。您可以尝试编写简单的解析器来提取您感兴趣的内容。我玩过并得到了这个:
import json
json_str = """
variable = [["1","arbitrary string","another arbitrary string"],
["2","arbitrary string","another arbitrary string"],
["3","arbitrary string","another arbitrary string"],
["4","arbitrary string","another arbitrary string"]];
another_variable = "arbitrary string";
"""
json_str_list = [js.strip().split("=")[1] for js in json_str.split(";") if js.strip()]
print("=preprocessed: %r" % json_str_list)
print("=json decoded: %r" % [json.loads(js) for js in json_str_list])
输出是:
=preprocessed: [' [["1","arbitrary string","another arbitrary string"],\n["2","arbitrary string","another arbitrary string"],\n["3","arbitrary string","another arbitrary string"],\n["4","arbitrary string","another arbitrary string"]]', ' "arbitrary string"']
=json decoded:
[
[[u'1', u'arbitrary string', u'another arbitrary string'],
[u'2', u'arbitrary string', u'another arbitrary string'],
[u'3', u'arbitrary string', u'another arbitrary string'],
[u'4', u'arbitrary string', u'another arbitrary string']],
u'arbitrary string']