0

速度を使用して、配列を次のように宣言します。

#set ($MyArray={
  'Index1':{'Field1':'value1','field2':'value2'},
  'Index3':{'Field1':'A value','field2':'Another value'}
})

例で「Index2」エントリを追加するにはどうすればよいですか:

'Index2':{'Field1':'A new value','field2':'Another new value'}"

または、値を変更できますか (たとえば、'Index 1'.field2')?

助けてくれてありがとう

4

1 に答える 1

0

$MyArray は配列変数ではなくマップです (Thxs to Marius): http://docs.oracle.com/javase/7/docs/api/java/util/Map.html

次に、答えは次のとおりです。

#set ($MyArray={
  'Index1':{'Field1':'value1','field2':'value2'},
  'Index3':{'Field1':'A value','field2':'Another value'}
})
$MyArray.getClass().getName()
* Original map
$jsontool.serialize($MyArray)
* I Modify the 'Index3' entrie:
#set ($discard=$MyArray.put('Index3',{'Field1':'A modified value','field2':'Another modified value'}))
$jsontool.serialize($MyArray)
* I add the 'Index2' entrie:
#set ($discard=$MyArray.put('Index2',{'Field1':'Addon value','field2':'Another addon value'}))
$jsontool.serialize($MyArray)
于 2015-07-27T10:05:55.590 に答える