我将JSONObject转换为字符串,以便在杰克逊中与杰克逊解析,但我的JSONObject中有一个列表,当我用ObjectMapper解析时,我得到了这个:
["{Property1 : value1, Property2 : value2}"]
而且我不能打电话给myJsonNodeObject.get(i).get("Property1")
,这是我的问题。
我试图将我的列表强制转换为JSONObject中的JSONArray,但不起作用。
resultAsJSONObject = new JSONObject();
resultAsJSONObject.put("Label", getMetricStatisticsResult.getLabel());
resultAsJSONObject.put("Datapoints", getMetricStatisticsResult.getDatapoints());
resultAsJSONObject.put("fromDate", fromDate.getTimeInMillis());
resultAsJSONObject.put("toDate", toDate.getTimeInMillis());
resultAsJSONObject.put("error", "");
resultAsString = resultAsJSONObject.toString();
mapper.readValue(resultAsString, MetricsData.class);
ObjecNode
,然后进行修改。这是一个例子: