1 快速上手

2 JFinalConfig

3 Controller

4 AOP

5 ActiveRecord

6 Enjoy 模板引擎

7 EhCachePlugin

8 RedisPlugin

9 Cron4jPlugin

10 Validator

11 国际化

12 Json 转换

13 JFinal架构及扩展

14 升级到 5.1.2

12.4 Json 转换用法

    json 转换在 jfinal 中的使用分为两类用法,第一类是使用配置的 json 转换,第二类是指定某个实现进行 json 转换。

1、使用配置的 json 实现转换

    如下代码将使用前面章节中介绍的配置的 json 实现进行转换:

// 在 Controller 中使用 renderJson 进行 json 转换,并渲染给客户端
renderJson();
renderJson(key, object);
renderJson(new String[]{...});

// 使用 JsonKit 工具类进行 json 转换
JsonKit.toJson(...);
JsonKit.parse(...);

2、使用指定的 json 实现转换

    如果下代码将使用指定的 json 实现去转换:

// 临时指定使用 FastJson 实现
FastJson.getJson().toJson(...);
FastJson.getJson().parse(...);

// 为 Controller.renderJson(..) 方法直接传入转换好的 json string
renderJson(FastJson.getJson().toJson(...));

    上面这种用法可以临时摆脱配置的 json 实现,从而使用指定的 json 实现。