• hb_jsonencode / hb_jsondecode with date values

    From Pere Cordonet@21:1/5 to All on Tue Sep 28 06:07:28 2021
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to pereco...@gmail.com on Tue Sep 28 08:14:24 2021
    On Tuesday, September 28, 2021 at 7:07:29 AM UTC-6, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.

    Hi Pereco:

    When compiled with xHarbour under BCC 7.4 , the result is a numeric: 2459306 (Number of days since base date ???)
    When compiled under Harbour under MInGW, the result is a Character string: "20210401"

    -Mel Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ella Stern@21:1/5 to pereco...@gmail.com on Tue Sep 28 13:04:18 2021
    On Tuesday, September 28, 2021 at 4:07:29 PM UTC+3, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.

    In JavaScript and in JSON there is no "date" primitive data type - you need to convert your date value into string.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ella Stern@21:1/5 to pereco...@gmail.com on Tue Sep 28 13:01:52 2021
    On Tuesday, September 28, 2021 at 4:07:29 PM UTC+3, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.

    In JavaScript and in JSON there is no "date" primitive data type - you need to convert your date value into string before converting it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pere Cordonet@21:1/5 to All on Tue Sep 28 23:13:01 2021
    El dia dimarts, 28 de setembre de 2021 a les 22:04:19 UTC+2, Ella Stern va escriure:
    On Tuesday, September 28, 2021 at 4:07:29 PM UTC+3, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.
    In JavaScript and in JSON there is no "date" primitive data type - you need to convert your date value into string.

    Good morning,

    I found the problem.
    I'm compile with xhb.com.

    In file "hbjson.c" at function "_hb_jsonEncode", i changed the order of " else if( HB_IS_DATE( pValue ) )" before of " else if( HB_IS_NUMERIC( pValue ) )" and work fine.

    It's strange, but works.

    Can you make this changes to repository?

    Thank you
    Pere.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to pereco...@gmail.com on Wed Sep 29 08:22:43 2021
    On Wednesday, September 29, 2021 at 12:13:02 AM UTC-6, pereco...@gmail.com wrote:
    El dia dimarts, 28 de setembre de 2021 a les 22:04:19 UTC+2, Ella Stern va escriure:
    On Tuesday, September 28, 2021 at 4:07:29 PM UTC+3, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.
    In JavaScript and in JSON there is no "date" primitive data type - you need to convert your date value into string.
    Good morning,

    I found the problem.
    I'm compile with xhb.com.

    In file "hbjson.c" at function "_hb_jsonEncode", i changed the order of " else if( HB_IS_DATE( pValue ) )" before of " else if( HB_IS_NUMERIC( pValue ) )" and work fine.

    It's strange, but works.

    Can you make this changes to repository?

    Thank you
    Pere.

    Hi Pere Cordonet:
    I confirm that the change you made to hbjson.c corrects the error-- so that the return is the character string "20210401" Good detective work !
    However, I have no idea *why* it works ?? !!
    Because in this particular section of the code, the Harbour version is identical to the original code in xHarbour. !
    I don't understand how the (pValue) can be both NUMERIC *and* DATE at the same time.
    What is happening here ???
    -Mel Smith

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mel Smith@21:1/5 to Mel Smith on Wed Sep 29 12:15:57 2021
    On Wednesday, September 29, 2021 at 9:22:44 AM UTC-6, Mel Smith wrote:
    On Wednesday, September 29, 2021 at 12:13:02 AM UTC-6, pereco...@gmail.com wrote:
    El dia dimarts, 28 de setembre de 2021 a les 22:04:19 UTC+2, Ella Stern va escriure:
    On Tuesday, September 28, 2021 at 4:07:29 PM UTC+3, pereco...@gmail.com wrote:
    Hello,
    I have a problems with date values when i call hb_jsonencode and hb_jsondecode

    After call hb_jsondecode date value is a number value.

    Can anyone test this code?

    Function Main()
    Local cJson,xVar

    SetMode( 24 , 80 )

    SET DATE BRITISH
    Set(_SET_DATEFORMAT,"DD/MM/YYYY")

    cJson:= hb_jsonencode( {"DATE"=> Stod("20210401") } )

    Hb_jsondecode( cJson , @xVar )
    ? xVar["DATE"]

    Return

    Thank you.
    In JavaScript and in JSON there is no "date" primitive data type - you need to convert your date value into string.
    Good morning,

    I found the problem.
    I'm compile with xhb.com.

    In file "hbjson.c" at function "_hb_jsonEncode", i changed the order of " else if( HB_IS_DATE( pValue ) )" before of " else if( HB_IS_NUMERIC( pValue ) )" and work fine.

    It's strange, but works.

    Can you make this changes to repository?

    Thank you
    Pere.
    Hi Pere Cordonet:
    I confirm that the change you made to hbjson.c corrects the error-- so that the return is the character string "20210401" Good detective work !
    However, I have no idea *why* it works ?? !!
    Because in this particular section of the code, the Harbour version is identical to the original code in xHarbour. !
    I don't understand how the (pValue) can be both NUMERIC *and* DATE at the same time.
    What is happening here ???
    -Mel Smith

    Hi Luiz
    Can you investigate this problem reported by Pere Cordonet ?
    Thank you.
    -Mel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)