我有一個宏從JIRA(作爲JSON對象)接收整個問題信息並將其打印在Confluence中。但是在Confluence中,新的線條丟失了,格式變得糟糕透頂。丟失新行符號( r n)
這是吉拉的文本(和它的外觀):
報告通過FTP之後發送到英傑風險管理團隊。
Aviva風險團隊使用每日報告提取部分數字 以及投資組合的風險表現報告。
這是它的外觀在JSON:
報告是事後通過FTP發送到英傑風險管理 團隊\ r \ n \ r \ nAviva風險團隊使用的每日報告中提取。一些 數字和組合的風險表現的報告。
而這就是後來被印:
報告通過FTP之後發送到英傑風險管理團隊。 Aviva風險團隊使用每日報告提取 中的一些數字以及投資組合風險表現的報告。
所以基本上,我從中得到的結果是,\n\r
符號丟失或不能在Confluence中轉換。我該如何解決這個問題?
編輯:@Octopus這是代碼。
public class FieldinfoMacro implements Macro {
@Override
@SuppressWarnings("unchecked")
// This macro gets the issue's field values from the page's context so you don't have to
// make new requests to Jira for each field seperately
public String execute(Map<String, String> par, String s, ConversionContext conversionContext)
throws MacroExecutionException {
// parameters
String add = (String) par.get("getfield").toLowerCase();
HashMap<String, String> fieldMap = (HashMap<String, String>) conversionContext.getProperty("fieldMap");
JSONObject issue = (JSONObject) conversionContext.getProperty("issueJson");
Object output = null;
Object result = null;
StringBuilder temp = new StringBuilder();
/* if (add.equals("reporter") || add.equals("assignee") || add.equals("account manager")) {
try {
output = issue.getJSONObject("fields").get(fieldMap.get(add));
result = ((JSONObject) output).get("emailAddress");
result = ((String) result).replaceAll("@.*", "");
result = ((String) result).replaceAll("\\W", " ");
} catch (JSONException je) {
je.printStackTrace();
}
} else { */
// get the requested field value from the issue
// there's a handler for the different types of returned data
// i.e. JSONObject, JSONArray, String
try {
output = issue.getJSONObject("fields").get(fieldMap.get(add));
// String handler
if (output instanceof String) {
result = output;
// JSONArray handler (covered different cases)
} else if (output instanceof JSONArray) {
for (int i = 0; i < ((JSONArray) output).length(); i++) {
if (((JSONArray) output).get(i) instanceof JSONObject) {
result = ((JSONArray) output).getJSONObject(i).getString("value");
} else {
if (((JSONArray) output).length() < 2) {
temp.append(((JSONArray) output).getString(i));
} else if (i < ((JSONArray) output).length() - 1) {
temp.append(((JSONArray) output).getString(i) + ", ");
} else temp.append(((JSONArray) output).getString(i));
result = temp;
}
}
// JSONObject handler
} else if (output instanceof JSONObject) {
result = ((JSONObject) output).getString("value");
}
} catch (JSONException je) {
je.printStackTrace();
}
return result.toString();
}
由於[JSON不能存儲多行字符串](http://gun.io/blog/multi-line-strings-in-json/),JSON編碼形式並不讓我感到意外。「打印的內容」似乎是由於印刷處理器無法正確處理換行符而導致的。 – fvu