spring mvcごとに.jspにjsonノードの(文字列、オブジェクト)を含むハッシュマップを解析するにはどうすればよいですか?
コントローラ:
Map<String, Object> foo = new HashMap<String, Object>();
o o o
// foo stores json node within the map
System.out.println( ( (JsonNode) foo.get("theKey")).toString() ); // Ouput-> "[100]"
System.out.println( ( (JsonNode) foo.get("theKey")).path(0).getIntValue() ); //Output-> "100"
//add to view model tag
model.addAttribute("foo", foo);
.jsp
<h1>${foo.get("theKey").path(0).getIntValue()}</h1> // <- Returns 0! Why?
編集:これらはすべて機能します
<h1>${foo["theKey"].path(0).getIntValue()}</h1> // OK! Returns 100.
<h1>${foo["theKey"].toString()}</h1> // NO ERROR and returns "[100]"
<h1>${foo["theKey"].path(0).toString()}</h1> // OK! Returns 100.
============================
さらにコンテキストを追加するには、次の json からマップを作成します。
// rootNode contains all the json below...iterates and assigns to map.
for (JsonNode node : rootNode) {
foo.put(node.path("key").getTextValue(), node.path("values"));
}
json
[
{
"key":"theKey",
"values":[
100
]
}
]