json

Post Reply
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

json

Post by Colin Haig »

Hi All
I am working with an api for a accounting package - I can extract information from the accounting package




if oHttp:open()
cItems2 := oHttp:ReadAll()
MEMOWRIT( "MYRESULT1.TXT", cItems2)
this is what the text file shows

{
"UID": "17ef4d73-cfa7-43fb-afe6-5350cbffffa9",
"CompanyName": "Techdata Software",
"IsIndividual": false,
"DisplayID": "TEC01",
"IsActive": true,
"Addresses": [
{
"Location": 1,
"Street": "32 Pingrup Lane\r\nScarborough ",
"City": null,
"State": "WA",
"PostCode": "6019",
"Country": null,
"Phone1": "08 9245 8945",
"Phone2": null,
"Phone3": null,
"Fax": null,
"Email": null,
"Website": null,
"ContactName": "Colin Haig",
"Salutation": "Mr"
}
],
}
I can then get the companyname

hb_jsondecode(cItems2,@hJson)
MsgInfo(hJson["CompanyName"]) displays "TechData Software"

I need to modify the companyname or change the contact name and then be able to post back

oHttp:Post(hJson,cUri)

Regards

Colin
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: json

Post by Daniel Garcia-Gil »

Hello

you can use hJson

hb_jsondecode(cItems2,@hJson)

hJson["CompanyName"] = "My New Company Name"

cJson = hb_JsonEncode(hJson)

oHttp:hFields["Content-Type"] = "application/json"

now you can post

oHttp:Post(hJson,cUri)
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: json

Post by Colin Haig »

Hi Daniel

cJson = hb_JsonEncode(hJson)

What should the valtype of cJson be. ?

oHttp:hFields["Content-Type"] = "application/json"

now you can post

I presume cJson shoud be passed to the post method not hJson

oHttp:Post(hJson,cUri)

I am still having issues with the update

METHOD PostByVerb( xPostData, cQuery, cVerb ) CLASS TIPClientHTTP


IF ::inetErrorCode( ::SocketCon ) == 0
MsgInfo('here')
::inetSendAll( ::SocketCon, cData )
::bInitialized := .T.
RETURN ::ReadHeaders()
else
MsgInfo(::inetErrorCode( ::SocketCon ))
ENDIF

::ReadHeaders() - always return .f.

METHOD ReadHeaders( lClear ) CLASS TIPClientHTTP

cLine := ::inetRecvLine( ::SocketCon, @nPos, 500 )

cLine is always empty
IF Empty( cLine )
// In case of timeout or error on receiving
RETURN .F.
ENDIF


Thanks for your suggestion.


Regards

Colin
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: json

Post by Daniel Garcia-Gil »

Colin Haig wrote: I presume cJson shoud be passed to the post method not hJson
Colin
yes right, sorry my mistake
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
Post Reply