数据库中的workExp(工作经历)字段是带换行或回车的字符串。再取出拼json的时候,换行会破坏json格式。于是先将该字符串中的换行或是回车替换成“;”,将替换好的字符串拼入json字符串中,传入前台再将“;”换成换行符即可。主要代码如下:
后台:
//workexp 工作经历中包含换行,进行处理后放入json字符串中。
BufferedReader br = new BufferedReader(new StringReader(user.getWorkExp().trim()));
String sting ="";
try
{
String line = br.readLine();
while(line != null){
sting += line+';';
line = br.readLine();
}
br.close();
} catch (IOException e)
{
e.printStackTrace();
}
前台:
var workexp = node.attributes.workExp.replace(/;/g,"\n");
parent.document.getElementById("WorkExp").value=workexp;