Home > Mobile >  serilization daughter classes
serilization daughter classes

Time:01-17

I am trying to serialize a class that has daughter classes but it does not allow me when I go to complete the json it gives me an error

This is the json file as it should look:

{
  "User": "jhuan.caasillas",
  "Passwd": "#########",
  "IdAplicativo": 2001,
  "Firma": "asdlkhg=saldkja=="
}




"Mensaje": {
        "CodigoMensaje": 320,
        "DescMensaje": "Exito"
    },
    "Roles": [
        {
            "Descripcion": "juan casillas"
        },
        {
            "Descripcion": "al21"
        },
        {
            "Descripcion": "comandos"
        },
        {
            "Descripcion": "identificado"
        }
    ]
}

I have this class with these methods created enter image description here

when I go to fill these methods with the json it doesn't allow me and I get the error

Cannot implicitly convert type 'serialize.Roles' to 'serialize.Roles[]' serialize

enter image description here

I would like to know how I can fill the json array that I showed previously

CodePudding user response:

If Roles is array it must be initialized as array

DominioRes res1 = new DominioRes
{
    Roles = new Roles[]
    {
        new Roles
        {
            Description="juan casillas"
        },
        new Roles
        {
            Description="al21"
        },
        new Roles
        {
            Description="comandos"
        },
        new Roles
        {
            Description="identificado"
        }
    }
};
  • Related