1
I am generating a JSON
in Delphi
with mORMot
and I need to pick it up on a page to generate some graphics with Google Chart
, however the Delphi
return me the JSON
within a result
. I just mount the string into a function with a return of the type RawJSON
. He 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 the JSON this way:
var jsonData = $.ajax({
url: 'http://localhost/api/graficos',
dataType: "json",
async: false
}).responseText;
Console.log(jsonData) I printed what? Ever tried to put jsonData.result? See Fiddle what I did here.
– Marconi
It didn’t work, take a look at the Fiddle, i put the code. If you remove "result" from JSON it works.
– Wendel Rodrigues
In Delphi, declare Data.Dbxplatform no uses, in your function where you generate the JSON put the following Getinvocationmetadata() code. Responsecode := 200; Getinvocationmetadata(). Responsecontent := Result.Tostring;
– Jefferson Rudolf