[英]How to use LazyList's toJson method with json arrays?
I'm doing a one to many association with two tables: "usuarios" and "rol" here there is no problem, the issue is that I'm using the function "toJson" to convert the result of the consult to a String with json format, just like this: 我正在与两个表进行一对多关联:“ usuarios”和“ rol”在这里没有问题,问题是我正在使用函数“ toJson”将咨询的结果转换为json格式,如下所示:
[
{
"activo":1,
"alta":null,
"contrasenia":"AA123.aa",
"edicion":null,
"editor_alta":null,
"editor_edicion":null,
"email":"dadadada@ssfsfds",
"id_division":0,
"id_pools":1,
"id_roles":2,
"id_usuarios":1234567895,
"nombre":"Javier",
"primer_apellido":"a",
"segundo_apellido":"a",
"parents":{
"rols":[
{
"activo":1,
"alta":"2019-07-08",
"concepto":"Administrador Pool",
"descripcion":"Usuario que gestiona a los agentes",
"edicion":null,
"editor_alta":1111111111,
"editor_edicion":null,
"id_permisos":2,
"id_roles":2
}
]
}
}
]
But i only want to get some of the params in the json, for example I only want to have the "id_usuarios" and the "parents{rols[conecepto]}" params, so I indicate in the toJson method the name of this params but the result json is something like this: 但是我只想在json中获取一些参数,例如,我只想拥有“ id_usuarios”和“ parents {rols [conecepto]}”参数,因此我在toJson方法中指出了该参数的名称但是结果json是这样的:
[
{
"id_usuarios":1234567895,
"concepto":null,
"parents":{
"rols":[
{
"activo":1,
"alta":"2019-07-08",
"concepto":"Administrador Pool",
"descripcion":"Usuario que gestiona a los agentes",
"edicion":null,
"editor_alta":1111111111,
"editor_edicion":null,
"id_permisos":2,
"id_roles":2
}
]
}
}
]
As you can see it is not obtaining the "concepto" param, and it is including all the params of "parents". 如您所见,它没有获得“概念”参数,而是包括了“父母”的所有参数。
So, is there any way to get just some parameters?, and how can i access to the values of the parents{rols} parameters? 那么,有什么方法可以获取一些参数吗?如何访问parent {rols}参数的值?
I am using this code to create the json string 我正在使用此代码创建json字符串
LazyList<Usuarios> usuarios = Usuarios.where("activo = 1").include(Rol.class);
String json = usuarios.toJson(true, "id_usuarios","concepto");
``
The LazyList.toJson()
documentation can be found here: http://javalite.github.io/activejdbc/snapshot/org/javalite/activejdbc/LazyList.html#toJson-boolean-java.lang.String...- LazyList.toJson()
文档可在以下位置找到: http : LazyList.toJson()
Looks like you are getting the correct result. 看来您得到的是正确的结果。 If your
concepto = null
then maybe it is in fact NULL
in the database? 如果您的
concepto = null
那么实际上数据库中它是否为NULL
? Did you look into that? 你调查了吗?
Also, the attribute list is applied to the current model, and not to children or parents, which means that under parents node you are going to get all attributes. 同样,属性列表将应用于当前模型,而不应用于子项或父项,这意味着您将在“父项”节点下获取所有属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.