Unable to convert a Json Object to JArray

Hi guys, I’m stuck developing an API integration where I can’t convert the Json Object to an Array:

1) Requisition result that works:

{
  "result": [
    {
      "u_bot_ip_name": "xxx",
      "u_number": "xxxx",
      "u_bot_host_name": "xxx",
      "sys_mod_count": "x",
      "u_bot_chassi": "xxxxxx",
      "sys_updated_on": "2021-09-03 16:21:09",
      "sys_tags": "",
      "u_bot_status_exec": "xx",
      "u_bot_time_exec": "1970-01-01 00:00:43",
      "u_bot_created_on_ref": "2021-08-19 18:16:33",
      "u_bot_number_ref": "xxx",
      "u_bot_razao_social": "xxx",
      "u_bot_solicitacao": "xxx",
      "sys_id": "022c59561b02fc10b0a8da02f54bcb3f",
      "u_bot_codigo_af": "xx",
      "sys_updated_by": "xxx,
      "u_bot_data_exec": "2021-09-03 13:21:08",
      "sys_created_on": "2021-08-20 16:06:28",
      "u_bot_updated_on_ref": "2021-08-20 10:56:16",
      "u_bot_environment_name": "xxxx",
      "u_bot_user_name": "xxx",
      "sys_created_by": "xxxx"
    }
  ]
}

2) Result of Requisition that Doesn’t Work:

{
  "data": {
    "TableA": {
      "numeroIdentificacaoRegistro": xx,
      "uf": "xx",
      "cnpjAgenteFinanceiro": "xxxxxxxxxxxxxx",
      "chassi": "xxxxxxxxxxxxx",
      "numeroSequenciaGravame": "xxxxxxxx",
      "descricaoTipoRestricao": "xxxxx",
      "descricaoTipoOperacao": "111",
      "dataInclusao": "2021-09-06T18:42:12",
      "dataControleIntegracaoRegistro": null,
      "dataControleIntegracaoGuia": null,
      "dataControleIntegracaoTaxa": null,
      "dataControleIntegracaoUpload": null,
      "descricaoChaveUpload": "xxxxxxx"
    },
    "TableB": {
      "nomeAgenteFinanceiro": "xxxxx",
      "numeroIdentificacaoMunicipioEmpresaPagamento": null,
      "codigoAgenteFinaceiroDetran": null,
      "codigoAgenteFinanceiro": "xxxxxx",
      "textoSenhaDetran": null,
      "dataHoraUltimaExecucao": null,
      "dataInicioPeriodo": null,
      "dataFimPeriodo": null,
      "descricaoDiretorioArquivo": null,
      "tempoDecorridoExecucaoRobo": null,
      "descricaoEstadoExecucao": null,
      "nomeEstacaoTrabalhoAmbiente": null,
      "numeroIpEstacaoTrabalhoAmbiente": null,
      "nomeEstacaoTrabalhoRoboExecutado": null,
      "nomeLoginUsuarioLogado": null
    },
  "sucesso": true,
  "mensagens": null,
  "paginacao": null
}

After deserializing Json and exporting the output to a JsonObject variable (in_sng_JsonObj)
I’m not able to convert the content to JArray

At runtime I get the following error:
Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JArray'

Need to perform this conversion to use the data in a For Each…

I suspect that the problem is due to the existence of table names in the second example, but I don’t know how to get around this characteristic of the data.

Can anyone give me a guide?

give a try on


grafik

Hi, I understand the concept a little bit and I can point out the contents of each Table following your tips, but I need to put all the table data in a JArray to perform the loop

@Rafaeloneil
there is no JArray. We can detect it on missing [ ]
We’re sure that we can help you on the case.

as shown in the screenshots - loop over the properties and filter out property names e.g. starting with Table in the name.

Use the calculated names, iterate over it and do the object access with it.

So you see we can bringt within loops. Other things like filling up a JArray / Lists etc can be done as well. But lets start first with above described approach

It worked! Through your tips I managed to set up the process. Thanks!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.