hb_jsondecode() bug on prg encode is 'big5', decode fail!!

250 views
Skip to first unread message

wen....@gmail.com

unread,
Oct 4, 2025, 6:44:48 AMOct 4
to harbou...@googlegroups.com
sample prg:

func main()
local hData := {"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}
// local cJson := hb_jsonEncode( hData ) // <--- is ok
local cJson := '{"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}' // is fail!!
local hJson := {=>}, i
? 'json string-1: ',cJson
hJson := hb_jsonDecode( cJson )
aJson := hb_hKeys(hJson)
? 'json len: ', Len(aJson)
FOR i := 1 TO Len(aJson)
? i,':',hb_hKeyAt( hJson, i ), '=>', hb_hValueAt( hJson, i )
NEXT i

//
? 'json string-2: ',cJson
// cJson := hb_StrReplace( cJson, {'\'}, {'\\'} )
hJson := hb_jsonDecode( cJson )
aJson := hb_hKeys(hJson)
? 'json len: ', Len(aJson)
FOR i := 1 TO Len(aJson)
? i,':',hb_hKeyAt( hJson, i ), '=>', hb_hValueAt( hJson, i )
NEXT i
return


test.prg

Nelson Pires

unread,
Oct 7, 2025, 12:01:10 PMOct 7
to harbou...@googlegroups.com
Maybe this ?

local cJson := '{"err_no":-1,"errmsg":"無法辨識的功能!!","errtil":"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}'

 

Nelson

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/20251004184440.EE86.CA28FD01%40gmail.com.

wen....@gmail.com

unread,
Oct 9, 2025, 9:39:37 PMOct 9
to harbou...@googlegroups.com
Chinese character "功", ASCII code is 'A5 5C'
 
日期(On) Tue, 7 Oct 2025 17:00:23 +0100
Nelson Pires <infor...@gmail.com> 寫信(write):
 
?
Maybe this ?

local cJson := '{"err_no":-1,"errmsg":"無法辨識的功能!!","errtil":"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}'

?

Nelson

wen....@gmail.com <wen....@gmail.com> escreveu (sabado, 4/10/2025 a(s) 11:44):
sample prg:

func main()
local hData := {"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}
// local cJson := hb_jsonEncode( hData )? // <--- is ok

local cJson := '{"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}' // is fail!!
local hJson := {=>}, i
? ? ? ? 'json string-1: ',cJson
? ? ? ? ? ? ? ? ? ? ? ? hJson := hb_jsonDecode( cJson )
? ? ? ? ? ? ? ? ? ? ? ? aJson := hb_hKeys(hJson)
? ? ? ? ? ? ? ? ? ? ? ? ? 'json len: ', Len(aJson)
? ? ? ? ? ? ? ? ? ? ? ? FOR i := 1 TO Len(aJson)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i,':',hb_hKeyAt( hJson, i ), '=>', hb_hValueAt( hJson, i )
? ? ? ? ? ? ? ? ? ? ? ? NEXT i

? ? ? //
? ? ? ? ? ? ? ? ? ? ? ? ? 'json string-2: ',cJson
? ? ? // cJson := hb_StrReplace( cJson, {'\'}, {'\\'} )
? ? ? ? ? ? ? ? ? ? ? ? hJson := hb_jsonDecode( cJson )
? ? ? ? ? ? ? ? ? ? ? ? aJson := hb_hKeys(hJson)
? ? ? ? ? ? ? ? ? ? ? ? ? 'json len: ', Len(aJson)
? ? ? ? ? ? ? ? ? ? ? ? FOR i := 1 TO Len(aJson)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i,':',hb_hKeyAt( hJson, i ), '=>', hb_hValueAt( hJson, i )
? ? ? ? ? ? ? ? ? ? ? ? NEXT i

return


--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/20251004184440.EE86.CA28FD01%40gmail.com.

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

Nelson Pires

unread,
Oct 10, 2025, 6:02:52 AMOct 10
to harbou...@googlegroups.com
Sorry, i was not clear. what i mean is using : instead of => in the string declaration


Alex Strickland

unread,
Oct 10, 2025, 8:42:47 AMOct 10
to harbou...@googlegroups.com
Hi

As Nelson Pires says, this is not valid JSON:

'{"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}'

You are using Harbour hash syntax.

--

Regards

Alex
Message has been deleted

wen....@gmail.com

unread,
Oct 10, 2025, 10:48:52 PMOct 10
to Harbour Users

local cJson := '{"err_no":-1,"errmsg":"無法辨識的功能!!","errtil":"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}' 
or:

local cJson := '{"err_no"=>-1,"errmsg"=>"無法辨識的功能!!","errtil"=>"錯誤!!(3bc8d2ca-a101-4585-afae-a35d483c0796)"}'

all fail!!

Alex Strickland 在 2025年10月10日 星期五晚上8:42:47 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages