JSON-taglib 是 JSP 2.0 标签库,用于生产 JSON (JavaScript Object Notation) 数据结构。
使用方法:
把 Json-taglib.jar 到 WEB-INF/lib目录
下面是一个示例:
<json:object>
<json:property name
=
"
outer
"
value
=
"
foo
"
/>
<json:object name
=
"
inner
"
>
<json:property name
=
"
innerProp1
"
value
=
"
val1
"
/>
<json:property name
=
"
innerProp2
"
value
=
"
val2
"
/>
<json:object name
=
"
inner2
"
>
<json:property name
=
"
inner2Prop1
"
value
=
"
in2p1
"
/>
<json:property name
=
"
inner2Prop2
"
value
=
"
in2p2
"
/>
</json:object>
</json:object>
</json:object>
输出的内容如下:
{
"
outer
"
:
"
foo
"
,
"
inner
"
: {
"
innerProp1
"
:
"
val1
"
,
"
innerProp2
"
:
"
val2
"
,
"
inner2
"
: {
"
inner2Prop1
"
:
"
in2p1
"
,
"
inner2Prop2
"
:
"
in2p2
"
}
}
}
JSON Arrays
使用数组
<json:object>
<json:array name
=
"
days
"
items
=
"
${days}
"
/>
<json:array name
=
"
bools
"
items
=
"
${bools}
"
/>
<json:array name
=
"
numbers
"
items
=
"
${numbers}
"
/>
</json:object>
输出的结果:
{
"
days
"
:
[
"Mon","Tue","Wed","Thur","Fri","Sat","Sun"
]
,
"
bools
"
:
[
true,false,true
]
,
"
numbers
"
:
[
1,2,3
]
}
JSON-taglib 官网: http://json-taglib.sourceforge.net/