当我们把List对象转化为json字符串时,我们返回如下所示:
[
{"id":1,"usrId":14,"productId":5},
{"id":8,"usrId":14,"productId":7},
{"id":11,"usrId":14,"productId":8}
]
但是dataTables需要的是如下形式的json数据:
{"data":
[
{"id":1,"usrId":14,"productId":5},
{"id":8,"usrId":14,"productId":7},
{"id":11,"usrId":14,"productId":8}
]
}
所以我们在将List对象转化为json字符串时,要进行字符串拼接。
使用字符串转义:
String json="{\"data\":"+listJsonString+"}";