FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to Save Json data to dbf? (Solved)
Posts: 85
Joined: Wed Nov 19, 2014 01:04 PM
How to Save Json data to dbf? (Solved)
Posted: Tue Oct 11, 2016 12:08 PM

Dear Sirs

How can I save following json data to dbf ?

{"ok":true,"result":[{"XXXX5086":8673,
"message":{"message_id":4,"from":{"id":294425086,"first_name":"Yunus","last_name":"Dagia"},"chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476180184,"text":"\/text","entities":[{"type":"bot_command","offset":0,"length":5}]}},{"XXXX5086":8674,
"message":{"message_id":5,"from":{"id":294425086,"first_name":"Yunus","last_name":"Dagia"},"chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476180228,"text":"hi"}},{"XXXX5086":8675,
"message":{"message_id":8,"from":{"id":294425086,"first_name":"Yunus","last_name":"Dagia"},"chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476187294,"text":"How to Save Json to dbf"}}]}

Thanks & Regards
Yunus

Regards

Yunus



FWH 21.02
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: How to Save Json data to dbf?
Posted: Tue Oct 11, 2016 12:18 PM

in memo field.

Regards

Posts: 85
Joined: Wed Nov 19, 2014 01:04 PM
Re: How to Save Json data to dbf?
Posted: Tue Oct 11, 2016 12:42 PM

Dear Sir, Hampauito

I want to replace certain value in particular field from json data

for example fields , message_id , id, , textmsg etc.

Regards
Yunus

Regards

Yunus



FWH 21.02
Posts: 470
Joined: Fri Feb 05, 2010 11:30 AM
Re: How to Save Json data to dbf?
Posted: Tue Oct 11, 2016 01:42 PM

Esto funcióna correctamente:

FUNCTION NEXO()
LOCAL URL:="http://xxx.xxx.xxx.xxx/testing/distribuidora/webservice/api/obtenerProductos"
LOCAL oDoc:=CreateObject("MSXML2.DOMDocument")
LOCAL oHttp:=CreateObject("MSXML2.XMLHTTP"),cRespuesta,aProductos:=""
oHttp:Open("GET",URL,.F.)
oHttp:SetRequestHeader("Accept" ,"application/xml")
oHttp:SetRequestHeader("Content-Type","application/json")
oDoc:async:=.f.
oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
oHttp:Send(oDoc:xml)
cRespuesta:=Alltrim(oHttp:responseText)
hb_jsondecode(cRespuesta,@aProductos)
XBROWSE(aProductos["productos"])
RETURN NIL

De la matriz aProductos, la puedes llevar a la DBF.
Espero te sea útil...

Roberto

Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.ar
Posts: 4
Joined: Tue Oct 11, 2016 03:16 PM
Re: How to Save Json data to dbf?
Posted: Tue Oct 11, 2016 08:08 PM
I believe that to do something like:

JSON DATA

Code (fw): Select all Collapse
{"ok":true,
 "result":[
   {"XXXX5086":8673,
   "message":
      {"message_id":4,"from":
         {"id":294425086,"first_name":"Yunus","last_name":"Dagia"},
         "chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476180184,"text":"\/text","entities":[{"type":"bot_command","offset":0,"length":5}]}},
   
   {"XXXX5086":8674,
   "message":
      {"message_id":5,"from":
         {"id":294425086,"first_name":"Yunus","last_name":"Dagia"},"chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476180228,"text":"hi"}},
   
   {"XXXX5086":8675,
   "message":
      {"message_id":8,"from":
         {"id":294425086,"first_name":"Yunus","last_name":"Dagia"},"chat":{"id":294425086,"first_name":"Yunus","last_name":"Dagia","type":"private"},"date":1476187294,"text":"How to Save Json to dbf"}
    }
 ]
}


To save

Code (fw): Select all Collapse
FUNCTION SaveJSONData(cJSON)
LOCAL hJSON



cDBFFrom := "from"
cDBFChat := "chat"

HB_JSONDecode( cJSON, @hJSON )

FOR i := 1 TO Len( hJSON["result"] )
    
    hData := hJSON["result"][i]["message"]
    nMessageID := hData["message_id"]
    
    hFrom := hData["from"]

    FOR EACH x IN hFrom 
        (cDBFFrom)->&x:__enumKey() := x
    NEXT

    hChat := hData["chat"]

    FOR EACH x IN hChat
        (cDBFChat)->&x:__enumKey() := x
    NEXT
    
    
NEXT

RETURN
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to Save Json data to dbf?
Posted: Wed Oct 12, 2016 04:00 AM
Posts: 85
Joined: Wed Nov 19, 2014 01:04 PM
Re: How to Save Json data to dbf?
Posted: Wed Oct 12, 2016 10:54 AM

Dear Anser,

I followed sample provide by Mr.Rao but... following error accrued

Error BASE/1003 Variable does not exist: TRUE
hHash := &cStr <= error accure on this line.

May be the structure of json string of Mr.Rao is different than mine.

Regards
Yunus.

Regards

Yunus



FWH 21.02
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: How to Save Json data to dbf?
Posted: Thu Oct 13, 2016 05:03 PM
Try

Code (fw): Select all Collapse
cStr:= StrTran(StrTran(cStr, ":false", ".F."), ":true", ".T.")


Regards
Posts: 85
Joined: Wed Nov 19, 2014 01:04 PM
Re: How to Save Json data to dbf?
Posted: Thu Oct 13, 2016 05:19 PM

Dear hmpaquito

Thanks for your reply.

I couldn't understand multi layer HASH jo just use simple string.

Telegram API using fivewin (without using any LIB)

viewtopic.php?f=3t=33056

Regards
Yunus.

&

Regards

Yunus



FWH 21.02

Continue the discussion