How to use multiple data from json objects

How to use multiple data from json objects

celsomtrindadecelsomtrindade Posts: 4Questions: 2Answers: 1

Hey guys,
so what i'm trying to do is to call some data from a json file to fill my table. But instead of having a lot of json files, i'd like to keep some of the data on the same one. For example, i have 2 types of clients (person and company) and i want to keep them both in the same json, but as different objects, because each one goes in a different table.

The problem is: I can't access the data in the JSON file.

I can use it normally if i use the 2 type of clients in different files (person.json and company.json - This works fine).

So, how can i do get the data from the file? Here is my json and my datatable code:

{
    "nm_cliente": {
        "person": [
            {
                "cd":0,
                "id":"C-0010",
                "nm_cliente":"Name AAA",
                "dt_nasc":"02/11/1990",
                "info":"Some basic info"
            },
            {
                "cd":1,
                "id":"C-0013",
                "nm_cliente":"Name BBB",
                "dt_nasc":"02/11/1990",
                "info":"Some basic info"
            },
            {
                "cd":2,
                "id":"C-0017",
                "nm_cliente":"Name CCC",
                "dt_nasc":"02/11/1990",
                "info":"Some basic info"
            }
        ],
        "company": [
            {
                "cd":0,
                "id":"C-0032",
                "nm_cliente":"Name Client",
                "num_cnpj":"111.222.3333/0001-22",
                "nm_cidade":"City AAA"
            },
            {
                "cd":1,
                "id":"C-0033",
                "nm_cliente":"Client Name",
                "num_cnpj":"111.222.3333/0001-22",
                "nm_cidade":"City BBB"
            },
            {
                "cd":2,
                "id":"C-0035",
                "nm_cliente":"jEmpresa teste",
                "num_cnpj":"111.222.3333/0001-22",
                "nm_cidade":"City CCC"
            }
        ]
    }
}

I already used jsonlint.com to verify, and everything is ok with my JSON.
And here is how i'm trying to call this data into my tables.

TableA - Client type Person

    //rest of the code goes here...
"aoColumns" : [
    { "mData": "person.id" },
    { "mData": "person.nm_cliente" },
    { "mData": "person.dt_nasc" },
    { "mData": "person.info" }
]

TableB - Client type Company

    //rest of the code goes here...
"aoColumns" : [
    { "mData": "company.id" },
    { "mData": "company.nm_cliente" },
    { "mData": "company.nm_cnpj" },
    { "mData": "company.nm_cidade" }
]

I keep getting error like "lenght not defined"

Can anyone help me?

This discussion has been closed.