在JSON父文档上添加JSONOrderedObject时,我遇到了一个问题(在Java开发下)。下面显示的代码显示了如何在Java中创建两个JSON对象(第一个是第二个文档中定义的字段所需的格式配置,以便正确显示)
final JSONOrderedObject numberFormat2= new JSONOrderedObject();
numberFormat2.put("@odata.type","#ContentFieldNumberFormat");
numberFormat2.put("DecimalSeparator","Period");
numberFormat2.put("UseThousandSeparator", false);
StringWriter out = new StringWriter();
numberFormat2.write(out);
System.out.println(out);
final JSONOrderedObject reportTemplateJSONObject = new JSONOrderedObject()
.put("@odata.type","StandardReportTemplate")
.put("ShowColumnHeaders", true)
.put("Name", "reportTemplateName")
.put("Headers", new JSONArray())
.put("Trailers", new JSONArray())
.put("ContentFields",
new JSONArray()
.put(new JSONObject().put("FieldName", "RIC").put("Format", JSONObject.NULL))
.put(new JSONObject().put("FieldName", "Shares Amount").put("Format", numberFormat2)))
.put("Condition", new JSONOrderedObject().put("ReportDateRangeType", "Range")
.put("QueryStartDate", "fromDate")
.put("QueryEndDate", "endDate")
.put("ExcludeDeletedEvents", true)
.put("IncludeCapitalChangeEvents", true)
.put("IncludeDividendEvents", true)
.put("IncludeEarningsEvents", true)
.put("IncludeMergersAndAcquisitionsEvents", true)
.put("IncludeNominalValueEvents", true)
.put("IncludePublicEquityOfferingsEvents", true)
.put("IncludeSharesOutstandingEvents", true)
.put("IncludeVotingRightsEvents", true)
.put("CorporateActionsCapitalChangeType", "CapitalChangeExDate")
.put("CorporateActionsDividendsType", "DividendPayDate")
.put("CorporateActionsEarningsType", "PeriodEndDate"));
StringWriter out3 = new StringWriter();
reportTemplateJSONObject.write(out3);
System.out.println(out3);
我还添加了一些东西来显示每个对象的内容
对于子文档,一切都显示正常,如下所示:
"@odata.type":"#ContentFieldNumberFormat","DecimalSeparator":"Period","UseThousandSeparator":false}
但是当它插入到父文档中时,内容被引号括起来(并且它们中的任何一个都被反斜杠转义)
{"@odata.type":"StandardReportTemplate","ShowColumnHeaders":true,"Name":"reportTemplateName","Headers":[],"Trailers":[],"ContentFields":[{"Format":null,"FieldName":"RIC"},{"Format":"{\"@odata.type\":\"#ContentFieldNumberFormat\",\"DecimalSeparator\":\"Period\",\"UseThousandSeparator\":false}","FieldName":"Shares Amount"}],"Condition":{"ReportDateRangeType":"Range","QueryStartDate":"fromDate","QueryEndDate":"endDate","ExcludeDeletedEvents":true,"IncludeCapitalChangeEvents":true,"IncludeDividendEvents":true,"IncludeEarningsEvents":true,"IncludeMergersAndAcquisitionsEvents":true,"IncludeNominalValueEvents":true,"IncludePublicEquityOfferingsEvents":true,"IncludeSharesOutstandingEvents":true,"IncludeVotingRightsEvents":true,"CorporateActionsCapitalChangeType":"CapitalChangeExDate","CorporateActionsDividendsType":"DividendPayDate","CorporateActionsEarningsType":"PeriodEndDate"}}
(注意下面显示的上述摘录)
{"Format":"{\"@odata.type\":\"#ContentFieldNumberFormat\",\"DecimalSeparator\":\"Period\",\"UseThousandSeparator\":false}"
对我做错了什么的想法?
谢谢!