FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Archivo JSON
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Archivo JSON
Posted: Tue Aug 23, 2016 11:27 AM
Hola amigos,
me env铆an un archivo JSON a una direcci贸n de internet:

'http://xxx.xxx.xxx.xxx/testing/distribuidora/webservice/api/obtenerProductos'

y necesito descargar la info y parsearla para descargarla en mi sistema, estuve leyendo
y probando ejemplos con el hb_JsonDecode, pero no puedo hacerla funcionar con mi
direcci贸n, probablemente me est茅 faltando informaci贸n.

Alguien tendr谩 un ejemplo para construir esta descarga?

Desde ya, muchas gracias!
Roberto
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Archivo JSON
Posted: Tue Aug 23, 2016 12:03 PM
Si puedes descargarlo a tu equipo y despues analizarlo
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()
聽 聽 聽 聽 
聽 聽local nRet
聽 聽local cFile 聽:= "c:\fwh\temp.txt" 
聽 
聽 聽nRet := DOWNLOADFILE( "http://xxx.xxx.xxx.xxx/testing/distribuidora/webservice/api/obtenerProductos/archivo.json", ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cFile 聽)
聽 聽 MsgStop( nRet )

RETURN NIL

#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>
#include "hbapiitm.h"
#include "hbstack.h"
#include <hbvm.h>
#include <urlmon.h>
HB_FUNC( DOWNLOADFILE )

{
聽 聽HRESULT hr;

聽 聽hr = URLDownloadToFile( NULL, hb_parc( 1 ), hb_parc( 2 ), 0, NULL );
聽 
聽 聽hb_retnl( hr ) ;
}

#pragma ENDDUMP

Es una idea nomas... no se si te deja un archivo en ese sitio...
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: Archivo JSON
Posted: Tue Aug 23, 2016 12:15 PM

Gracias! Perfecto!!!!!

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: Archivo JSON (Encode)
Posted: Wed Aug 24, 2016 07:15 PM

Amigos,
despu茅s de decodificar un JSON que me enviaron, debo actualizar info y volverla
a generar en JSON.
Tengo una matriz, que contiene el C贸digo del Art铆culo, Descripci贸n y Precio Unitario, por ejemplo.
Como hago para volver a generar un archivo JSON para subirlo a una url?
Creo que se usa la funci贸n inversa hb_JsonEncode, pero no encuentro material
para ver los par谩metros que se usan...
Muchas gracias!
Roberto

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Archivo JSON
Posted: Wed Aug 24, 2016 07:22 PM
Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: Archivo JSON
Posted: Wed Aug 24, 2016 07:28 PM

Eso lo us茅 para descargar el Json, ahora necesito armar un archivo Json... se entiende?
El proceso inverso... subir info de una matriz a un archivo Json.
Gracias!
Roberto

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: Archivo JSON
Posted: Wed Aug 24, 2016 08:13 PM

Amigos... lo hice medio casero... pero funciona, capaz hay algo un poco m谩s sofisticado...
Por ah铆 le sirve a alguno:

FUNCTION GENERARJSON()
Local hJson := hash()
local cJson := '{"clientes":['
(bclientes)->(dbgotop())
while !(Bclientes)->(eof())
hJson["C贸digo"] := (bclientes)->codigo
hJson["Raz贸n Social"] := alltrim(hb_OemToAnsi((bclientes)->NOMBRE))
hJson["Direcci贸n"] := alltrim(hb_OemToAnsi((bclientes)->direccion))
hJson["Tel茅fono"] := alltrim((bclientes)->te)
hJson["C.U.I.T."] := alltrim((bclientes)->cuit)
cJson += hb_JsonEncode( hJson,.f. )
(bclientes)->(dbskip())
IF !(Bclientes)->(eof())
cJson +=","
ENDIF
enddo
cJson+=']}'
MemoWrit( "clientes.json", cJson )
RETURN NIL

Saludos...

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 196
Joined: Tue Jul 01, 2008 06:34 PM
Re: Archivo JSON
Posted: Fri Aug 26, 2016 12:36 AM
Buenas noches

En que libreria est谩 hb_JsonEncode( )

Gracias
Luis Ponce
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: Archivo JSON
Posted: Fri Aug 26, 2016 12:42 PM

Es una funci贸n de Harbour...
Saludos

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 336
Joined: Wed May 16, 2007 09:40 PM
Re: Archivo JSON
Posted: Tue Oct 24, 2023 06:40 PM
LuisPonce wrote:Buenas noches

En que libreria est谩 hb_JsonEncode( )

Gracias
Hola

sabes en que libreria esta y desde que version,,, tengo entendido que funciona tanto en Harbour como en Xharbour
Fivewin-Xharbour 24.09, Iquique, Chile

Continue the discussion