How do I access this Json?

Asked

Viewed 43 times

0

{
    "success": {
    "data": [
      {
        "IdContribuinte": "1",
        "IdContribuinteTributario": "1",
        "IdUsuarioAnalisando": null,
        "DataAtualizacaoTributario": null,
        "DataImportacao": "2018-01-12 14:09:26.507",
        "Nivel": "0",
        "Status": "AN",
        "StatusDescricao": "ANALISAR",
        "TipoPessoa": "J",
        "TipoPessoaDescricao": "JURÍDICA",
        "Nome": "PREFEITURA MUNICIPAL DE MARILIA",
        "CpfCnpj": "44.477.909/0001-00",
        "RgIe": null,
        "DataNascimento": null,
        "DataFalecimento": null,
        "Falecido": "0",
        "NomeMae": null,
        "Cep": "17501-900",
        "Endereco": "RUA BAHIA, 40 ",
        "Logradouro": "RUA BAHIA",
        "Numero": "40",
        "Complemento": "",
        "Bairro": "MARÍLIA",
        "Cidade": "MARILIA",
        "Uf": "SP",
        "Telefone": "3402-6000",
        "Email": null,
        "UsuarioAnalisando": null
      },
      {
        "IdContribuinte": "2",
        "IdContribuinteTributario": "100000",
        "IdUsuarioAnalisando": null,
        "DataAtualizacaoTributario": null,
        "DataImportacao": "2018-01-12 14:09:26.507",
        "Nivel": "0",
        "Status": "AN",
        "StatusDescricao": "ANALISAR",
        "TipoPessoa": "F",
        "TipoPessoaDescricao": "FÍSICA",
        "Nome": "JOSE ALVES FILHO",
        "CpfCnpj": "791.910.028-34",
        "RgIe": "9930556",
        "DataNascimento": null,
        "DataFalecimento": null,
        "Falecido": "0",
        "NomeMae": null,
        "Cep": "17522-270",
        "Endereco": "RUA EDUARDO PRADO, 279 ",
        "Logradouro": "RUA EDUARDO PRADO",
        "Numero": "279",
        "Complemento": "",
        "Bairro": null,
        "Cidade": "MARILIA",
        "Uf": "SP",
        "Telefone": null,
        "Email": null,
        "UsuarioAnalisando": null
      }
    ]
    "feedback_msg" => "successo"
}

I want to access this json, I get it from a re-act prop,

const list = this.props.list || []
console.log(list.success.data[0].Nome)

but I’m not getting access

  • What’s being returned here: console.log(list.success.data[0].Nome)?

  • is returning this here Uncaught Typeerror: Cannot read Property 'data' of Undefined at Contribuinteslist.renderRows (app.js:40511) at Contribuinteslist.render (app.js:40553) at app.js:24050 at measureLifeCyclePerf (app.js:23329) at Reactcompositecomponentwrapper. _renderValidatedComponentWithoutOwnerOrContext (app.js:24049) at Reactcompositecomponentwrapper. _renderValidatedComponent (app.js:24076) at Reactcompositecomponentwrapper.performInitialMount (app.js:23616)

  • If I use console.log(list.Success), it returns this below {data: Array(100), feedback_msg: null} data : Array(100) 0 : {Idcontributor: "1", Idcontributortax: "1", Idusuarioanalyzing: null, Dataupdateotributario: null, Dataimport: "2018-01-12 14:09:26.507", ... } 1 :

  • And if you use console.log(list.success.data)?

  • tried ja, app.js:40511 Uncaught Typeerror: Cannot read Property 'data' of Undefined

  • 1

    console.log(list) gives what exactly ? You won’t be catching the [] that comes from || ?

  • It’s my first question, so I get a little lost when it comes to digesting the codes, but my json is this one, which I move from the back end to the front $result = ['Success' => [ 'data' => $re-signageImovel, 'feedback_msg' => 'Contributor records for re-signage' ]];

  • 1

    This JSON is invalid.

  • If you control the backend and have the code that generates JSON put it also in the question because it is relevant. Just as @Valdeirpsr indicated, the JSON you have in the question is invalid, so the problem starts there

  • i’m getting it normal on the front, I access, this.props.list.Success it functiona, if I put . date it doesn’t work

Show 5 more comments

1 answer

0

console.log(action.payload.data.success.data[0])
const INITIAL_STATE = {list: []}
export default (state = INITIAL_STATE, action) => {
    switch (action.type) {
        case 'CONTRIBUINTES_FETCHED':
        console.log(action.payload.data.success.data[0])
        return { ...state, list: action.payload.data.success }
        default:
        return state
    }
}

I got access, further inside the contributing fileReducer I was trying to access inside the contributor.jsx receiving the object by props.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.