Like reading a JSON on Harbour?

Asked

Viewed 127 times

2

In PHP, to interpret a JSON file for the language, we can use the function json_decode. Already in Javascript, we can use JSON.parse.

What about Harbour? Is there a role to interpret JSON?

Example:

Procedure Main()
   LOCAL json := '{"nome": "Wallace"}'
   ? json
   Return

1 answer

3


Decoding with hb_JsonDecode

The Harbour already has native function for this:

hHash := hb_JsonDecode( cJson )

Example:

hData := hb_JsonDecode( '{"Wallace":"Maxters","Score":100000}' )
? hData['Wallace']

Upshot:

Maxters


Coding with hb_JsonEncode

cJson := hb_JsonEncode( xData )

Example:

? hb_JsonEncode( {'teste' => 123} )

Upshot:

{"teste":123}

Still, have formatted result option:

hb_jsonEncode( xValue [, lHuman = .F. | nIndent = 0 ] ) --> cJSON

the second parameter can be .T. for tabulation, or numeric for indenting with spaces


Implementation:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.