Page 1 of 1

How to Save Json data to dbf? (Solved)

Posted: Tue Oct 11, 2016 12:08 pm
by dagiayunus
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

Re: How to Save Json data to dbf?

Posted: Tue Oct 11, 2016 12:18 pm
by hmpaquito
in memo field.

Regards

Re: How to Save Json data to dbf?

Posted: Tue Oct 11, 2016 12:42 pm
by dagiayunus
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

Re: How to Save Json data to dbf?

Posted: Tue Oct 11, 2016 1:42 pm
by TOTOVIOTTI
Esto funcióna correctamente:

FUNCTION NEXO()
LOCAL URL:="http://xxx.xxx.xxx.xxx/testing/distribu ... rProductos"
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

Re: How to Save Json data to dbf?

Posted: Tue Oct 11, 2016 8:08 pm
by aflm
I believe that to do something like:

JSON DATA

Code: Select all

{"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


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 
 

Re: How to Save Json data to dbf?

Posted: Wed Oct 12, 2016 4:00 am
by anserkk
Here is an example provided by Mr.Rao
http://forums.fivetechsupport.com/viewt ... 19#p191101

Re: How to Save Json data to dbf?

Posted: Wed Oct 12, 2016 10:54 am
by dagiayunus
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.

Re: How to Save Json data to dbf?

Posted: Thu Oct 13, 2016 5:03 pm
by hmpaquito
Try

Code: Select all

cStr:= StrTran(StrTran(cStr, ":false", ".F."), ":true", ".T.")
Regards

Re: How to Save Json data to dbf?

Posted: Thu Oct 13, 2016 5:19 pm
by dagiayunus
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)
http://forums.fivetechsupport.com/viewt ... =3&t=33056

Regards
Yunus.