Get JSON return without "result" in Ajax or return without "result" in Delphi

0

I'm generating JSON in Delphi with mORMot and I need to get it on a page to generate graphics with Google Chart , but Delphi returns me JSON within a result . I just put the string in a function with a return of type RawJSON . It comes this way:

{
  "result":[
    {
      "cols":[
        {"id":"","label":"Mês","pattern":"","type":"string"},
        {"id":"","label":"Quantidade","pattern":"","type":"number"}
      ],
      "rows":[
        {"c":[{"v":"Agosto de 2016","f":null},{"v":191,"f":null}]},
        {"c":[{"v":"Setembro de 2016","f":null},{"v":188,"f":null}]},
        {"c":[{"v":"Outubro de 2016","f":null},{"v":230,"f":null}]},
        {"c":[{"v":"Novembro de 2016","f":null},{"v":243,"f":null}]},
        {"c":[{"v":"Dezembro de 2016","f":null},{"v":145,"f":null}]},
        {"c":[{"v":"Janeiro de 2017","f":null},{"v":245,"f":null}]},
        {"c":[{"v":"Fevereiro de 2017","f":null},{"v":206,"f":null}]},
        {"c":[{"v":"Março de 2017","f":null},{"v":174,"f":null}]},
        {"c":[{"v":"Abril de 2017","f":null},{"v":241,"f":null}]}
      ]
    }
  ]
}

But I need it so that's what I'm generating:

{
  "cols":[
    {"id":"","label":"Mês","pattern":"","type":"string"},
    {"id":"","label":"Quantidade","pattern":"","type":"number"}
  ],
  "rows":[
    {"c":[{"v":"Agosto de 2016","f":null},{"v":191,"f":null}]},
    {"c":[{"v":"Setembro de 2016","f":null},{"v":188,"f":null}]},
    {"c":[{"v":"Outubro de 2016","f":null},{"v":230,"f":null}]},
    {"c":[{"v":"Novembro de 2016","f":null},{"v":243,"f":null}]},
    {"c":[{"v":"Dezembro de 2016","f":null},{"v":145,"f":null}]},
    {"c":[{"v":"Janeiro de 2017","f":null},{"v":245,"f":null}]},
    {"c":[{"v":"Fevereiro de 2017","f":null},{"v":206,"f":null}]},
    {"c":[{"v":"Março de 2017","f":null},{"v":174,"f":null}]},
    {"c":[{"v":"Abril de 2017","f":null},{"v":241,"f":null}]}
  ]
}

On the page I get JSON this way:

var jsonData = $.ajax({
      url:      'http://localhost/api/graficos',
      dataType: "json",
      async:    false
    }).responseText;
    
asked by anonymous 22.05.2017 / 19:26

1 answer

0

I was able to solve using the JSON.parse in the result of the request, because it brings a string and the Google Charts expects an object:

var jsonData = JSON.parse(jsonData);

Then to get the JSON without the result I've called jsonData.result[0] , this shows what's inside result .

    
22.05.2017 / 21:46