将表示列表的字符串转换为 Jython 中的实际列表?

Converting a string that represents a list into an actual list in Jython?

我在 Jython 中有一个表示 JSON 数组列表的字符串:

[{"datetime": 1570216445000, "type": "test"},{"datetime": 1570216455000, "type": "test2"}]

如果我尝试遍历它,它只会遍历每个字符。我怎样才能让它遍历实际列表以便我可以得到每个 JSON 数组?

背景信息 - 此脚本在 Apache NiFi 中 运行,下面是字符串源自的代码:

from org.apache.commons.io import IOUtils
...    
def process(self, inputStream):
        text = IOUtils.toString(inputStream,StandardCharsets.UTF_8)

您可以像在 Python 中那样解析 JSON

示例代码:

import json

# Sample JSON text
text =  '[{"datetime": 1570216445000, "type": "test"},{"datetime": 1570216455000, "type": "test2"}]'

# Parse the JSON text
obj = json.loads(text)

# 'obj' is a dictionary
print obj[0]['type']
print obj[1]['type']

输出:

> jython json_string_to_object.py
test
test2