How can this be performed in xHarbour, I need this to help send parameters to json methods.
Thanks,
Byron ...
#include "Fivewin.ch"
Function Main()
aHash := hash()
ahash["ItemName"] = "Apple"
ahash["Quantity"] = 500
cJson := hb_jsonEncode(ahash,.T.) // .T. adds Line Feed to the output string, .F. without Linefeed
MsgInfo(cJson)
MsgInfo( hb_jsonEncode(.T.,.F.) ) // Output true
Return NIL
byron.hopp wrote:In your example:
aHash := hash()
ahash["ItemName"] = "Apple"
ahash["Quantity"] = 500
cJson := hb_jsonEncode(ahash,.T.) // .T. adds Line Feed to the output
Does cJson == (not sure about linefeeds)
{"ItemName": "Apple","Quantity": 500}
or
{
"ItemName": "Apple",
"Quantity": 500
}.
#include "Fivewin.ch"
Function Main()
aHash := hash()
ahash["ItemName"] = "Apple"
ahash["Quantity"] = 500
cJson := hb_jsonEncode(ahash,.T.)
MsgInfo(cJson)
/* Output with Parameter .T. ie hb_jsonEncode(ahash,.T.)
{
"ItemName": "Apple",
"Quantity": 500
}
*/
cJson := hb_jsonEncode(ahash,.F.)
MsgInfo(cJson)
/* Output with Parameter .F. ie hb_jsonEncode(ahash,.F.)
{"ItemName": "Apple","Quantity": 500}
*/
Return NIL
byron.hopp wrote:If this is true then I could probably write my own JsonStringify(), and JsonParse() but it would need to include more complex hash arrays.
btw, I don't have hb_JsonEncode(), or hb_JsonDecode() available in my version of xHarbour. I Downloaded the newest demo but there is no reference of these functions in the documentation. I sent an e-mail to the software company representing xHarbour and asked if these functions are included in the newest version and they indicated that they don't answer technical questions, and referred me to this news group. I really feel that this is a pre-sales question and not the focus of this group, but I appreciate the assistance in this group as always.
hLogin := GetEmptyHash()
cLogin := ""
hLogin["email" ] := "bhopp@matrixcomputer.com"
hLogin["password"] := "TheWord"
cLogin := JsonStringify( hLogin )
cLogin is: {"email": "bhopp@matrixcomputer.com","password": "TheWord"}
Function JsonStringify( hJson )
Local nI := 0
Local cJson := '{'
For nI := 1 to Len( hJson )
cJson += '"' + HGetKeyAt( hJson,nI ) + '": "' + HGetValueAt( hJson,nI) + '"' + IIF( nI < Len( hJson ),",","" )
Next
cJson += '}'
Return cJson
Thanks,
Byron ...
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 105 guests