Author | Topic: JSON OBJECT TO ARRAY | |
---|---|---|
![]() | César Calvo | JSON OBJECT TO ARRAY on Fri, 17 May 2024 21:03:47 +0200 Good afternoon, I have a JSON object that I would like to convert to an array. Is there a function that does it or hao could I try? I mean the way for get data of datos step by step {"error":0,"mensaje":"","datos[{"ean":"8432336602597","codigo":"90222005","cliente":491,"referencia":"90222005","descripcion":"CONVECTOR PORT\u00c1TIL CP-TURBO 2000W","precio":52,"marca":"491","url":"https:\/\/www.elnur.es\/convectores\/convector-portatil-cp-turbo\/","familia":"CALEFACCI\u00d3N","vigencia":"2024-05-01","actualizado":"2024-05-04","unidadventa":"1 u.","unidadprecio":52,"pedidoventa":"*","partidaestadistica":"","descuento":"*"},{"ean":"8432336602559","codigo":"90212005","cliente":491,"referencia":"90212005","descripcion":"TERMOVENTILADOR PORT\u00c1TIL TVH-2000","precio":20,"marca":"491","url":"https:\/\/www.elnur.es\/calefactores-termoventiladores\/termoventilador-ceramico-portatil-tvh\/","familia":"CALEFACCI\u00d3N","vigencia":"2024-05-01","actualizado":"2024-05-04","unidadventa":"1 u.","unidadprecio":20,"pedidoventa":"*","partidaestadistica":"","descuento":"*"}] Thanks. |
![]() | Andreas Gehrs-Pahl | Re: JSON OBJECT TO ARRAY on Wed, 22 May 2024 09:12:57 -0400 César, Your JSON string is invalid, as it is missing several characters. The following part: "datos[{ should actually be: "datos":[{ Also the closing } is missing at the very end. After you corrected that, you can create a DataObject that corresponds to the JSON string like this: cJSON := '......' oJSON := Json2Var(cJSON) The resulting oJSON DataObject contains three iVars: oJSON:error := 0 oJSON:mensaje := "" oJSON:datos := {DataObject, DataObject} The oJSON:datos iVar contains an array that contains two more DataObjects, with the following iVars: oJSON:datos[1]:ean := "8432336602597" oJSON:datos[1]:codigo := "90222005" [...] oJSON:datos[1]:descuento := "*" and oJSON:datos[2]:ean := "8432336602559" oJSON:datos[2]:codigo := "90212005" [...] oJSON:datos[2]:descuento := "*" Keep in mind that the original JSON file is in UTF-8 and will be converted to OEM or ANSI, depending on your settings, so the content of your DataObject might vary slightly from the original JSON file. You can also reverse that process with Var2JSON(). I hope that helps. Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas@AbsoluteSoftwareLLC.com web: http://www.AbsoluteSoftwareLLC.com [L]: https://www.LinkedIn.com/in/AndreasGehrsPahl [F]: https://www.FaceBook.com/AbsoluteSoftwareLLC |