I am using a webservice that responses with a JSON file with a PDF inside: ["certidaoPDF"].
Response Class (Status 200):
application/json;charset=UTF-8
{
"razaoSocial":"string",
"nomeFantasia":string,
"cnpj":"string",
"uf":string,
"certidoes": [
{
"emissor":"TCU",
"tipo":"string",
"dataHoraEmissao":"13/04/2018 16:38",
"descricao":"string",
"situacao":"string",
"observacao":"string"
}
],
"certidaoPDF":"application/pdf"
}
I am using xHarbour v1.2.1 and there´s no hb_jsonDecode lib so I use was using this function below but it doesn´t work in this case:
Function JSontoHash( cStringJson )
/***
* Convert string Json format to Hash
*/
Local hJson := {=>}
cStringJson := StrTran( cStringJson,':[','=>{')
cStringJson := StrTran( cStringJson,'":"','" => "')
cStringJson := StrTran( cStringJson,'[','{')
cStringJson := StrTran( cStringJson,']','}')
cStringJson := StrTran( cStringJson,'":null','"=>nil')
cStringJson := StrTran( cStringJson,'":true' ,'"=>.t.' )
cStringJson := StrTran( cStringJson,'":false','"=>.f.')
cStringJson := StrTran( cStringJson,'":','"=>')
cStringJson := StrTran( cStringJson,"\/","/" )
hJSon := &( cStringJson )
Return hJson
This is my code:
http := CreateObject("MSXML2.ServerXMLHTTP")
http:Open("GET", "https://certidoes-apf.apps.tcu.gov.br/api/rest/publico/certidoes/"+cCNPJ+"?seEmitirPDF=true", .F.)
http:send()
JSONCNPJ := http:responseText
hCNPJ := JSontoHash(JSONCNPJ) // RETURNS AN ERROR HERE
My objective is to download that PDF.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 61:10:14 |
Calls: | 6,654 |
Calls today: | 6 |
Files: | 12,200 |
Messages: | 5,331,524 |