【发布时间】:2015-01-06 13:49:07
【问题描述】:
我有一个看起来像这样的类:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class XYZ {
@JsonSerialize(using = ISODateSerializer.class)
private Date startDate;
@JsonSerialize(using = ISODateSerializer.class)
private Date endDate;
private Map<String, Object> other = new HashMap<String, Object>();
@JsonAnyGetter
public Map<String, Object> any() {
return other;
}
@JsonAnySetter
public void set(String name, Object value) {
other.put(name, value);
}
@JsonIgnore
public void setJsonMap(Map<String, Object> other) {
this.other = other;
}
}
我还有一个如下所示的 json 输出:
{
"startDate": "2014-08-23",
"endDate": "2014-08-24",
"sumOfOrderValuesSquared": 178,
"values": [
{
"position": 4,
"value": "your statement closing date in <b>March 2015</b>.",
"pValue": 0,
"rawValue": "your statement closing date in <b>March 2015</b>.",
"calculated": {
"conversionRateStdErr": 0,
"visitPercentage": 0.000016899313887856152,
"conversionRate": 0
}
},
{
"position": 5,
"value": "your statement closing date in <b>April 2015</b>.",
"pValue": 0,
"rawValue": "ass</b>.",
"calculated": {
"conversionRateStdErr": 0,
"visitPercentage": 0.000012,
"conversionRate": 0
}
}
]
}
现在我的问题是我需要遍历“值”对象。它以 arraylist 的形式出现,但我不知道 arraylist 的类型以及如何对其进行迭代,所以我无法对其进行迭代。
还有, 我正在使用 httpClient apache api 进行服务器到服务器的休息调用,但它没有陷入提琴手的陷阱。 我在 Windows 7 机器上使用 java 应用程序。任何想法。 谢谢
【问题讨论】:
-
你真的应该比初学者更好地设计你的课程。 “一刀切”
Map几乎从来都不是一个好的解决方案。
标签: java json rest jackson fiddler