Convert multiDimensional Array to Hash

237 views
Skip to first unread message

hherrera

unread,
Dec 27, 2016, 9:14:16 PM12/27/16
to Harbour Users
Hi Friends!!
How do I convert a multidimensional array to hash? 
Compatible with Json format?


Develop a code but I think it is not fully compatible

Example
AData: = {{"Fecha", "S"} ,;
               {"Poliza", "S"}
               .....
               .... }

And how do I record it to a .jsn file?


Develop a code but I think it is not fully compatible

FUNCTION fWriteHash(aData)
aJSonFormat:= hb_Hash( aData)
hb_MemoWrit("C:\data\myfile.jsn", aJSonFormat)
RETURN

the result is

[["Fecha","S"],["Póliza","S"],["Tipo Póliza","S"],["Total","S"],["Cerrado","S"],["Mayorizada","S"],["Cuadrada","S"],["Facturas","S"],["P","S"],["M","S"],["C","S"],["F","S"],["Tipo Doc.","S"],["Cuenta","S"],["Proyecto","S"],["No. Doc","S"],["Descripción","S"],["Id","S"]]


Thanks

Henry Herrera

Klas Engwall

unread,
Dec 27, 2016, 9:38:39 PM12/27/16
to harbou...@googlegroups.com
Hi Henry,
Here is an example:

//--------------------------------
procedure main()

local hJson := hb_hash(), cJson
local aData := { {"Fecha", "S"} ,;
{"Poliza", "S"} }
hJson[ "myarray" ] := aData
cJson := hb_jsonencode( hJson, .T. )
hb_memowrit( "json.txt", cJson )
return
//--------------------------------

And the result:

{
"myarray":
[
[
"Fecha",
"S"
],
[
"Poliza",
"S"
]
]
}

Regards,
Klas

hherrera

unread,
Dec 27, 2016, 10:35:22 PM12/27/16
to Harbour Users
ohh!!!  Wonderfull Thanks!
Reply all
Reply to author
Forward
0 new messages