How to Save Json data to dbf? (Solved)

How to Save Json data to dbf? (Solved)

Postby dagiayunus » 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
Last edited by dagiayunus on Sun Oct 16, 2016 9:40 pm, edited 1 time in total.
Regards
Yunus

FWH 21.02
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm

Re: How to Save Json data to dbf?

Postby hmpaquito » Tue Oct 11, 2016 12:18 pm

in memo field.

Regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: How to Save Json data to dbf?

Postby dagiayunus » 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
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm

Re: How to Save Json data to dbf?

Postby TOTOVIOTTI » Tue Oct 11, 2016 1: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.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 419
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: How to Save Json data to dbf?

Postby aflm » Tue Oct 11, 2016 8:08 pm

I believe that to do something like:

JSON DATA

Code: Select all  Expand view

{"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: Select all  Expand view


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
 
aflm
 
Posts: 4
Joined: Tue Oct 11, 2016 3:16 pm

Re: How to Save Json data to dbf?

Postby anserkk » Wed Oct 12, 2016 4:00 am

User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to Save Json data to dbf?

Postby dagiayunus » 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
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm

Re: How to Save Json data to dbf?

Postby hmpaquito » Thu Oct 13, 2016 5:03 pm

Try

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


Regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: How to Save Json data to dbf?

Postby dagiayunus » Thu Oct 13, 2016 5: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=3&t=33056

Regards
Yunus.
Regards
Yunus

FWH 21.02
dagiayunus
 
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 81 guests