InputStreamReader reader = null;
try {
try {
reader = new InputStreamReader(new FileInputStream(“E://1.xml”),”UTF-8″);
} catch (UnsupportedEncodingException e) {
logger.error(“读取文件路径异常”+e);
return null;
}
} catch (FileNotFoundException e) {
logger.error(“文件路径未找到”+e);
return null;
}
StringBuffer sb = new StringBuffer();
int ch = 0;
// 读取xml文件内容
try {
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
xml = sb.toString();
// 打包成json格式的数据,并进行相应的转换
int low = 97;
int upp = 65;
for (int j = 0; j < 25; j++) {
xml = xml.replaceAll(“_” + (char) low, “_” + (char) upp);
upp++;
low++;
}
xml:
<drinkOrder></drinkOrder><drinksOnly></drinksOnly><taxFlag1></taxFlag1><taxFlag2>Y</taxFlag2>
json:
“drinkOrder”:[],”drinksOnly”:[],”taxFlag1″:[],”taxFlag2″:”Y”
问题:当节点之间为空串时,就会把它解析成[],这个问题有什么办法能解决
try {
try {
reader = new InputStreamReader(new FileInputStream(“E://1.xml”),”UTF-8″);
} catch (UnsupportedEncodingException e) {
logger.error(“读取文件路径异常”+e);
return null;
}
} catch (FileNotFoundException e) {
logger.error(“文件路径未找到”+e);
return null;
}
StringBuffer sb = new StringBuffer();
int ch = 0;
// 读取xml文件内容
try {
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
xml = sb.toString();
// 打包成json格式的数据,并进行相应的转换
int low = 97;
int upp = 65;
for (int j = 0; j < 25; j++) {
xml = xml.replaceAll(“_” + (char) low, “_” + (char) upp);
upp++;
low++;
}
xml:
<drinkOrder></drinkOrder><drinksOnly></drinksOnly><taxFlag1></taxFlag1><taxFlag2>Y</taxFlag2>
json:
“drinkOrder”:[],”drinksOnly”:[],”taxFlag1″:[],”taxFlag2″:”Y”
问题:当节点之间为空串时,就会把它解析成[],这个问题有什么办法能解决
解决方案
40
用jackson试试