Hi Serge,
> I try to generate a JSON file from a DBF-file which should contain:
> - dbf structure (fieldnames)
> - dbf data
>
> This works and the generated file is OK according
http://jsonlint.com/
>
> When I try to reload the JSON file it gives: Error BASE/1068 Argument
> error: array access
>
> See the coding I use:
> Either my create is wrong or decode doesn't work properly? Can anybody
> please shine a light on this?
I can assure you that hb_JsonDecode() is working properly on a valid
json file. But ...
... I gave it a shot yesterday and tried to run your code. First I had
to replace your calls to the xHarbour function Hash() in three places.
Use Harbour functions instead (see the list below).
Then it stopped with:
Error DBFNTX/1001 Open error: P:\TEST\LANDEN.dbf (DOS Error 3)
Called from DBUSEAREA(0)
Called from CREATE_JSON(22)
Called from MAIN(4)
I didn't have time to investigate the code to see what that dbf file
should look like. If you post code here, we need it to be self contained
(== complete).
There are many hash related functions that can help you find out what is
wrong. hb_HHasKey() will tell you if a certain key exists, for example,
or hb_HPos() will tell you the hash member's position in the hash.
You are using macro substitution blindly to access the members of the
hash that you call "res". If you use hb_HPos() to find the member's
position you can exit gracefully if it is not found. Then hb_HGet() will
give you the value, or hb_HPairat() will give you both the key and the
value as an array.
Here is a list of all the available hash functions:
HB_HASH( [ <Key1>, <Value1> ], [ <KeyN>, <ValueN> ], ... ) -> <hsTable>
HB_HHASKEY( <hsTable>, <Key> [, @nPos ] ) --> <lFound>
HB_HPOS( <hsTable>, <Key> ) -> nPosition
HB_HGET( <hsTable>, <Key> ) -> <Value>
HB_HGETDEF( <hsTable>, <Key>, [<DefaultValue>] ) -> <Value>
HB_HSET( <hsTable>, <Key>, <Value> ) -> <hsTable>
HB_HDEL( <hsTable>, <Key> ) -> <hsTable>
HB_HKEYAT( <hsTable>, <nPosition> ) -> <Key>
HB_HVALUEAT( <hsTable>, <nPosition>, [<NewValue>] ) -> <Value>
HB_HPAIRAT( <hsTable>, <nPosition> ) -> <aKeyValue>
HB_HDELAT( <hsTable>, <nPosition> ) -> <hsTable>
HB_HKEYS( <hsTable> ) -> <aKeys>
HB_HVALUES( <hsTable> ) -> <aValues>
HB_HCLEAR( <hsTable> ) -> <hsTable>
HB_HFILL( <hsTable>, <Value> ) -> <hsTable>
HB_HCLONE( <hsTable> ) -> <hsDestination>
HB_HCOPY( <hsDestination>, <hsSource>, [<nStart>], [<nCount>] ) ->
<hsDestination>
HB_HMERGE( <hsDestination>, <hsSource>, <bBlock>|<nPosition> ) ->
<hsDestination>
HB_HEVAL( <hsTable>, <bBlock>, [<nStart>], [<nCount>] ) -> <hsTable>
HB_HSCAN( <hsTable>, <Value>, [<nStart>], [<nCount>, [<lExact>] ) ->
nPosition
HB_HSORT( <hsTable> ) -> <hsSortedTable>
HB_HCASEMATCH( <hsTable>, [<lFlag>] ) -> <lPreviousFlag>
HB_HBINARY( <hsTable>, [<lFlag>] ) -> <lPreviousFlag>
HB_HAUTOADD( <hsTable>, [<nAutoAdd>|<lAutoAdd>], [<xDefault>] ) ->
<nOldAutoAdd>
HB_HKEEPORDER( <hsTable>, [<lFlag>] ) -> <lPreviousFlag>
HB_HALLOCATE( <hsTable>, <nItems> )
HB_HDEFAULT( <hsTable>, <DefaultValue> ) -> <OldDefaultValye>
HB_HGETREF( <hsTable>, <Key>[, <@Value> ] ) -> <lFound>
HB_HSETORDER( <hsTable> [, <lNewSetting> ] ) -> <hsTable>
Regards,
Klas