Help in reading data from Hash

Help in reading data from Hash

Postby Ari » Wed May 10, 2023 2:08 pm

Hello friends !

I'm having trouble reading the json: I'd like to get the two records to play in the table. :oops:
Code: Select all  Expand view

{
  "total": 2,
  "rows":
  [
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "ANEL",
      "prodprincial": "14464080",
      "produto": "4J0522",
      "codfor": 274,
      "preco": 0.44,
      "ipi": 0
    },
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "FILTRO",
      "prodprincial": "1P2299",
      "produto": "1P2299",
      "codfor": 14498,
      "preco": 37.93,
      "ipi": 0
    }
  ]
}
 
Thanks,
Ari

FWH 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Ari
 
Posts: 234
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil

Re: Help in reading data from Hash

Postby nageswaragunupudi » Wed May 10, 2023 3:56 pm

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local cJson,hHash
   local aHead, aData

TEXT INTO cJson
{
  "total": 2,
  "rows":
  [
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "ANEL",
      "prodprincial": "14464080",
      "produto": "4J0522",
      "codfor": 274,
      "preco": 0.44,
      "ipi": 0
    },
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "FILTRO",
      "prodprincial": "1P2299",
      "produto": "1P2299",
      "codfor": 14498,
      "preco": 37.93,
      "ipi": 0
    }
  ]
}
ENDTEXT

   hHash := hb_jsonDecode( cJson )
   aHead := HGetKeys( hHash[ "rows" ][ 1 ] )
   aData := {}
   AEval( hHash[ "rows" ], { |hRow| AAdd( aData, HGetValues( hRow ) ) } )

   XBRoWSER aData SETUP ( oBrw:cHeaders := aHead )

return nil
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Help in reading data from Hash

Postby nageswaragunupudi » Wed May 10, 2023 3:56 pm

Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local cJson,hHash
   local aHead, aData

TEXT INTO cJson
{
  "total": 2,
  "rows":
  [
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "ANEL",
      "prodprincial": "14464080",
      "produto": "4J0522",
      "codfor": 274,
      "preco": 0.44,
      "ipi": 0
    },
    {
      "seunumero": 12345,
      "codcli": "3948",
      "qtde": 1,
      "descricao": "FILTRO",
      "prodprincial": "1P2299",
      "produto": "1P2299",
      "codfor": 14498,
      "preco": 37.93,
      "ipi": 0
    }
  ]
}
ENDTEXT

   hHash := hb_jsonDecode( cJson )
   aHead := HGetKeys( hHash[ "rows" ][ 1 ] )
   aData := {}
   AEval( hHash[ "rows" ], { |hRow| AAdd( aData, HGetValues( hRow ) ) } )

   XBRoWSER aData SETUP ( oBrw:cHeaders := aHead )

return nil
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Help in reading data from Hash

Postby Ari » Wed May 10, 2023 4:01 pm

Dear Rao,

God bless you you are the man.. when I posted I thought of Mr. !

Congratulations :D
Thanks,
Ari

FWH 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Ari
 
Posts: 234
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests