How to Save Json data to dbf? (Solved)

Post Reply
dagiayunus
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm
Contact:

How to Save Json data to dbf? (Solved)

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

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

Re: How to Save Json data to dbf?

Post by hmpaquito »

in memo field.

Regards
dagiayunus
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm
Contact:

Re: How to Save Json data to dbf?

Post 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
Regards
Yunus

FWH 21.02
User avatar
TOTOVIOTTI
Posts: 430
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina
Has thanked: 5 times

Re: How to Save Json data to dbf?

Post by TOTOVIOTTI »

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

Re: How to Save Json data to dbf?

Post by aflm »

I believe that to do something like:

JSON DATA

Code: Select all | Expand


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



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
 
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

Re: How to Save Json data to dbf?

Post by anserkk »

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

Re: How to Save Json data to dbf?

Post 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.
Regards
Yunus

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

Re: How to Save Json data to dbf?

Post by hmpaquito »

Try

Code: Select all | Expand

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


Regards
dagiayunus
Posts: 85
Joined: Wed Nov 19, 2014 1:04 pm
Contact:

Re: How to Save Json data to dbf?

Post 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)
viewtopic.php?f=3&t=33056

Regards
Yunus.
Regards
Yunus

FWH 21.02
Post Reply