0

![]() |
![]() |
Acabo de llegar... |
@fastpho, Hola, buenas tardes!, me podrás ayudar haciendo una prueba para ver si tenes el mismo error? (así descarto error humano). De los 4 campos que quiero recuperar solo me trae 2.
COBOL Código:
ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FILA PIC 9(8). 01 WFEC-AMD PIC X(10). 01 TIMPTOT PIC X(9). 01 WS. 02 WS-NRO PIC X(7). 02 WS-NRO-ORD REDEFINES WS-NRO PIC 9(7). 02 WS-ID PIC X(3). 02 WS-IDMPAGO REDEFINES WS-ID PIC 9(3). 01 WGET-VTA-FEC PIC X(20) IS GLOBAL VALUE "C:\APi\APIRFech1.TXT". PROCEDURE DIVISION. INICIO. INVOKE ChilkatJsonObject1 "LoadFile" USING WGET-VTA-FEC RETURNING ReturnValue. IF ReturnValue NOT = 1 THEN INVOKE pow-self "DisplayMessage" USING "error" EXIT PROGRAM END-IF. * INVOKE ChilkatJsonObject1 "SizeOfArray" USING "Objeto" RETURNING IndiceArray. MOVE ZEROS TO FILA FI-LA. PERFORM VARYING FILA FROM FILA BY 1 UNTIL FILA = IndiceArray OR FILA > 10 * MOVE SPACES TO ObJsolicitar STRING "Objeto[" delimited by size FILA delimited by size "]" delimited by size "." delimited by size "concretado" delimited by size into ObJsolicitar END-STRING INVOKE ChilkatJsonObject1 "StringOf" USING ObJsolicitar RETURNING WFEC-AMD * MOVE SPACES TO ObJsolicitar STRING "Objeto[" delimited by size FILA delimited by size "]" delimited by size "." delimited by size "idModoDePago" delimited by size into ObJsolicitar END-STRING INVOKE ChilkatJsonObject1 "StringOf" USING ObJsolicitar RETURNING WS-ID * INITIALIZE TIMPTOT WS-NRO WS-ID WFEC-AMD MOVE SPACES TO ObJsolicitar STRING "Objeto[" delimited by size FILA delimited by size "]" delimited by size "." delimited by size "idVenta" delimited by size into ObJsolicitar END-STRING INVOKE ChilkatJsonObject1 "StringOf" USING ObJsolicitar RETURNING WS-NRO MOVE SPACES TO ObJsolicitar STRING "Objeto[" delimited by size FILA delimited by size "]" delimited by size "." delimited by size "total" delimited by size into ObJsolicitar END-STRING INVOKE ChilkatJsonObject1 "StringOf" USING ObJsolicitar RETURNING TIMPTOT * DISPLAY WFEC-AMD " , " WS-ID " , " TIMPTOT " , " WS-NRO " , fila " fila END-PERFORM. EXIT PROGRAM.
Si podes probar te lo voy a agradecer.
Cualquier ayuda es bienvenida!!
Saludos
Ana
![]() |
![]() |
Senior |
Hola @AHidalgo, corri tu ejemplo y el unico valor que no me da es el total , para que te lo lea te
paso un ejemplo leyendo los dos primeros registros
de tu ejemplo la lineaCOBOL Código:
INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[0].total.moneda" RETURNING string-total display "total moneda :" , string-total INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[0].total.valor" RETURNING string-total display "total valor :" , string-total INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[0].total.idComercio" RETURNING string-total display "total idComercio :" , string-total INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[1].total.moneda" RETURNING string-total display "total moneda :" , string-total INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[1].total.valor" RETURNING string-total display "total valor :" , string-total INVOKE ChilkatJsonObject1 "StringOf" USING "Objeto[1].total.idComercio" RETURNING string-total display "total idComercio :" , string-total
esta mal ubicadaCOBOL Código:
INITIALIZE TIMPTOT WS-NRO WS-ID WFEC-AMD
Saludos
![]() |
![]() |
Acabo de llegar... |
@fastpho, Gracias!!, también he comprobado ejecutar con un control un VBScript con el parseo y funciona bien, pero intentaba hacerlo en cobol puro.
Saludos
Ana
![]() |
![]() |
Acabo de llegar... |
Buenas en mi caso necesito crear un JsonArray y dentro los JsonObject i no encuentro ningun ejemplo... alguien sabe la manera de poder declarar un JsonArray en netcobol
![]() |
![]() |
Senior |
Por ejemplo, para rellenar una tabla (concretamente de postgresql) que tiene una clave y tres campos con array alfabetico de 13, 3 y 3 elementos tal como así:
SQL Código:
CREATE TABLE entidadejercicio.configuracion4 ( clave numeric(1,0) NOT NULL, arqueo character varying(55) [13] NOT NULL, pie character varying(55) [3] NOT NULL, firma character varying(55) [3] NOT NULL );
Lo relleno con este codigo, para despues realizar un INSERT en la base de datos:
COBOL Código:
INITIALIZE msql STRING "INSERT INTO " delimited by size esquema delimited by " " "configuracion4 VALUES(0, '{" DELIMITED BY SIZE '"' delimited by size mun00-arqueo(1) '", "' delimited by size mun00-arqueo(2) '", "' delimited by size mun00-arqueo(3) '", "' delimited by size mun00-arqueo(4) '", "' delimited by size mun00-arqueo(5) '", "' delimited by size mun00-arqueo(6) '", "' delimited by size mun00-arqueo(7) '", "' delimited by size mun00-arqueo(8) '", "' delimited by size mun00-arqueo(9) '", "' delimited by size mun00-arqueo(10) '", "' delimited by size mun00-arqueo(11) '", "' delimited by size mun00-arqueo(12) '", "' delimited by size mun00-arqueo(13) '"}' delimited by size "'," delimited by size "'{" DELIMITED BY SIZE '"' delimited by size mun00-pie(1) '", "' delimited by size mun00-pie(2) '", "' delimited by size mun00-pie(3) '"}' delimited by size "'," delimited by size "'{" DELIMITED BY SIZE '"' delimited by size mun00-firmas(1) '", "' delimited by size mun00-firmas(2) '", "' delimited by size mun00-firmas(3) '"}' delimited by size "');" delimited by size INTO msql perform insertar
Básicamente el JSON generado es algo como así:
Código:{ "clave": 0, "arqueo": [ " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " ], "pie": [ " ", " ", " " ], "firma": [ " EL PRESIDENTE ", " EL INTERVENTOR ", " EL TESORERO " ] }
![]() |
![]() |
Senior |
Hola @Mane9mb, te paso un ejemplo en visual basic , no es muy dificil pasarlo a cobol
usando el control ocx de chilkat
Saludos ....VB Código:
Dim jArray As New ChilkatJsonArray success = jArray.AddObjectAt(0) Dim json As ChilkatJsonObject Set json = jArray.ObjectAt(0) success = json.UpdateString("groupId","") success = json.UpdateString("sku","") success = json.UpdateString("title","") success = json.UpdateString("barcode","") success = json.UpdateString("category","") success = json.UpdateString("description","") success = json.UpdateString("images[0]","url1") success = json.UpdateString("images[1]","url...") success = json.UpdateString("isbn","") success = json.UpdateString("link","") success = json.UpdateString("linkLomadee","") success = json.UpdateString("prices[0].type","") success = json.UpdateNumber("prices[0].price","0") success = json.UpdateNumber("prices[0].priceLomadee","0") success = json.UpdateNumber("prices[0].priceCpa","0") success = json.UpdateNumber("prices[0].installment","0") success = json.UpdateNumber("prices[0].installmentValue","0") success = json.UpdateString("productAttributes.""Atributo 1""","Valor 1") success = json.UpdateString("productAttributes.""Atributo ...""","Valor ...") success = json.UpdateString("technicalSpecification.""Especificação 1""","Valor") success = json.UpdateString("technicalSpecification.""Especificação ...""","Valor ...") success = json.UpdateNumber("quantity","0") success = json.UpdateNumber("sizeHeight","0") success = json.UpdateNumber("sizeLength","0") success = json.UpdateNumber("sizeWidth","0") success = json.UpdateNumber("weightValue","0") success = json.UpdateNumber("declaredPrice","0") success = json.UpdateNumber("handlingTimeDays","0") success = json.UpdateBool("marketplace",0) success = json.UpdateString("marketplaceName","") jArray.EmitCompact = 0 Debug.Print jArray.Emit() ' The output of this program is: ' [ ' { ' "groupId": "", ' "sku": "", ' "title": "", ' "barcode": "", ' "category": "", ' "description": "", ' "images": [ ' "url1", ' "url..." ' ], ' "isbn": "", ' "link": "", ' "linkLomadee": "", ' "prices": [ ' { ' "type": "", ' "price": 0, ' "priceLomadee": 0, ' "priceCpa": 0, ' "installment": 0, ' "installmentValue": 0 ' } ' ], ' "productAttributes": { ' "Atributo 1": "Valor 1", ' "Atributo ...": "Valor ..." ' }, ' "technicalSpecification": { ' "Especificação 1": "Valor", ' "Especificação ...": "Valor ..." ' }, ' "quantity": 0, ' "sizeHeight": 0, ' "sizeLength": 0, ' "sizeWidth": 0, ' "weightValue": 0, ' "declaredPrice": 0, ' "handlingTimeDays": 0, ' "marketplace": false, ' "marketplaceName": "" ' } ' ]
![]() |
![]() |
Acabo de llegar... |
Hola JCantero
Entiendo, pero en este caso solo tengo que tractar JSON han comentado en este post sobre el ocx de Chillkat JsonObject que facilita a la hora de tractar objetos JsON pero que empiece como un Json Array no lo encontrado por eso si teneis un ejemplo os lo agradezco, lo que me muestras es para hacer un insert a la base de datos? no trabajo con base de datos en cobol todo se guarda en archivos...
perdonadme es mi primer año que toco cobol ja que jo estoy encargado de la parte de lAPI @JCantero,
COBOL Código:
MOVE 0 TO "EmitCompact" OF ChilkatJsonArray1.COBOL Código:
MOVE 0 TO "EmitCompact" OF ChilkatJsonObject2.COBOL Código:
INVOKE ChilkatJsonArray1 "AddArrayAt" USING "customerStatus" "Prospect" RETURNING Success0.COBOL Código:
INVOKE ChilkatJsonObject2 "AppendString" USING "customerType" "Individual" RETURNING Success1.
![]() |
![]() |
Senior |
Fuera del destino del uso del JSON, o de su generación, yo he puesto un ejemplo de uso para su mejor comprension.
Quieres un ejemplo ?
Tienes un ejemplo de JSON con array en mi post. Al final....
Y @fastpho, tambien te ha puesto otro ejemplo de JSON con array al final de su post, lo que está en verde.
![]() |
![]() |
Acabo de llegar... |
@JCantero, Gracias por los ejemplos de verdad, pero lo que necesito es más como tractar esos objetos que define @fastpho, con el ocx que explica.
No he querido ni mucho menos menospreciar tu ayuda perdon si mhe explicado mal
Os lo agradezco mucho!
---------- Post añadido el 16 de junio de 2022 a las 14:17 ----------
Gracias, por su ayuda en tu ejemplo he podido pasarlo a cobol i que funcione,
con esta linea si ya tienes el json creado lo insertas dentro del arrayCOBOL Código:
INVOKE ChilkatJsonArray1 "AddObjectCopyAt" USING jsonArray ChilkatJsonObject2
Un saludo!![]()
Actualmente hay 1 usuarios viendo este tema. (0 miembros y 1 visitantes)