我正在将Json转换为Avro。 我的json数据在JSONArray
中。 在将其转换为字节数组时,我遇到了问题。
以下是我的代码:
static byte [] fromJsonToAvro(JSONArray json, String schemastr) throws Exception {
ExcelToJson ejj = new ExcelToJson();
List<String> list = new ArrayList<String>();
if (json != null) {
int len = json.length();
for (int i=0;i<len;i++){
list.add(json.get(i).toString());
}
}
InputStream input = new ByteArrayInputStream(list.getBytes()); //json.toString().getBytes()
DataInputStream din = new DataInputStream(input);
.
.
.//rest of the logic
那么我该怎么做呢? 如何将JsonArray对象转换为字节(即如何使用getBytes()方法处理JsonArray对象)。上述代码在list.getBytes()
处报错,并提示list未定义getBytes()方法。