简单的json格式数据在freemarker中可以直接解析,无需转为list。下面是简单示例:
1.嵌套的json解析
<div class="atricle-text">
<!--assign指令用于在页面上定义一个变量,这儿定义了一个名称为text的json格式变量,下面普通的json解析是属于后台传递过来的-->
<#assign text>
{"res":"0","msg":"OK","count":"3","pagenum":"1","pagesize":"1","totalpage":"1","userlist":[{"id":"1","name":"aa","sex":"男","age":"22"},{"id":"2","name":"bb","sex":"男","age":"21"},{"id":"3","name":"cc","sex":"女","age":"20"}]}
</#assign>
<#assign json=text?eval />
<#list json.userlist as item>
id:${item.id}, name:${item.name},sex:${item.sex}
</#list>
获取res:${json.res}
</div>
2.普通的json解析
[{"order":1,"pic":"https://abc.com/img/38841072000769","describe":"222222222"},{"order":1,"pic":"https://abc.com/img/38841040029953","describe":"222222222"},{"order":1,"pic":"https://abc.com/img/38841048046849","describe":"222222222"}]
<#assign json=ckworks.pics?eval />
<#list json as item>
<img src="${item.pic!}" alt="${item.describe}"/><br/>
</#list>
没错,就是这样子解析的,再见。