json

json

Postby Colin Haig » Mon Aug 25, 2014 2:10 am

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: json

Postby Daniel Garcia-Gil » Tue Aug 26, 2014 2:25 am

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)
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: json

Postby Colin Haig » Tue Aug 26, 2014 12:20 pm

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: json

Postby Daniel Garcia-Gil » Wed Aug 27, 2014 1:43 am

Colin Haig wrote:I presume cJson shoud be passed to the post method not hJson
Colin


yes right, sorry my mistake
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 24 guests