我有一个宏,它从JIRA (作为一个JSON对象)获取整个问题信息,并在Confluence中打印它。但是在“合流”中,新的行丢失了,格式也就下地狱了。
这是Jira中的文本(以及它的外观):
报告随后通过ftp发送给Aviva风险管理小组。 Aviva风险小组使用每日报告提取一些数字,并对投资组合的风险表现进行报告。
这就是它在JSON中的样子:
然后通过ftp将报告发送给Aviva风险管理小组。\r\n英杰瓦风险小组使用每日报告提取一些数字,并对投资组合的风险表现进行报告。
这就是后来印出来的东西:
报告随后通过ftp发送给Aviva风险管理小组。Aviva风险小组使用每日报告提取一些数字,并对投资组合的风险表现进行报告。
所以,基本上,我从这里得到的是,\n\r符号丢失了,或者没有翻译出它们在汇合点中应该用的方式。我怎么才能解决呢?
编辑:@八达通,这是密码。
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();
}发布于 2014-01-09 11:39:36
"\r\n“是Windows & Unix的遗物。使用Confluence,您需要换行的HTML标记,因为html将其他换行处理为单个空格。
因此,一个简单的result = ((String) result).replace("\r\n", "<br>");就能做到这一点。
发布于 2014-01-07 10:29:03
你不应该担心这个。JSON完全能够表示任何UTF-8字符。一旦收到JSON字符串,您肯定会在代码中执行一些操作,这将获得\r\n字符的区域。您应该能够通过编写逻辑将\r\n转换为新行,比如添加<br> html标记。请在文章中添加从JSON获取数据的方式,以便在页面中打印
这一行从字符串中移除所有‘\r\n’
result = ((String) result).replaceAll("\\W", " ");这就是字符串文本没有任何\r和\n字符的原因。请把那条线移开,然后进行测试。请注意,\W的意思是“任何非单词字符”。即不包括这些[a-zA-Z0-9_]字符的字符。希望这能有所帮助
https://stackoverflow.com/questions/20968942
复制相似问题