简体   繁体   English

如何在json数组中使用LazyList的toJson方法?

[英]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.

相关问题 如何将JSON解析为ActiveJDBC模型? - How to parse JSON into an ActiveJDBC Model? 如何在方法ActiveJDBC中将模型作为参数传递 - How to pass Model as an argument in a method ActiveJDBC 如何将 quarkus 与其他 ORM (activejdbc) 一起使用 - how to use quarkus with other ORM (activejdbc) ControllerRunner的执行顺序 - ControllerRunner's Execution order 是否可以在activejdbc中使用Long FK? - Is it possible to use Long FK in activejdbc? ActiveJDBC无法与Java Jersey的注释一起使用 - ActiveJDBC not working with Java Jersey's annotations 如何将连接池与ActiveJDBC结合使用,而不是每次都仅使用Base.open和close? - How do you use a Connection Pool with ActiveJDBC instead of just Base.open & close everytime? 当我尝试在生产环境上运行时,方法processOverridesBelongsTo上的ActiveJDBC Nullpointer异常 - ActiveJDBC Nullpointer exception on method processOverridesBelongsTo when I try to run on Production 在 ActiveJDBC 中模拟 findAll() 方法进行单元测试 - Mock findAll() method in ActiveJDBC for unit testing 如何在ActiveJDBC中锁定用户记录? 还是在使用Activejdbc事务时自动锁定? - How does one lock a user record in ActiveJDBC? Or is it autolocked when you use Activejdbc transactions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM