Title: JSON Return Post by: Gary C. on May 11, 2018, 01:41:58 pm Hi
Not sure if this belongs here or the BDL section but, I am trying to work with a restful web service from a carrier integration firm and I am struggling to manage their return results and am looking for some advice. Their documentation states: The response has 2 entries: one is a dictionary for errors and one a list of successful imports. Here are two examples of the response, the first is a successful call and the second an unsuccessful one: {"errors":{},"success":["000014298"]} {"errors":{"0":["identifier: Consignment with identifier already exists"]},"success":[]} In BDL, I am struggling to handle the dictionary element. Here is a snippet of my code: Code
In the event that the errors dictionary has any entries, I get a BDL error: JSON parse error: Unexpected '[', target is not an ARRAY I can see it is not, but what is the best construct to parse such a return value into? Thanks Gary Title: Re: JSON Return Post by: Reuben B. on May 14, 2018, 12:19:37 am There was a similar discussion here http://4js.com/support/forum/?topic=1186
You have not mentioned the proposeType method so I will just make sure you are aware of it http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ext_util_JSON_proposeType.html If you have used it, you will notice that it would return ... Code
... which is not valid syntax. proposeType was added in 3.00, DICTIONARY was added in 3.10, wether proposeType will ever propose DICTIONARY is a valid question? If you replace the 0 with DICTIONARY then you get a syntax error as DICTIONARY is expecting a data-type. I then tried creating a type as in the code below ... Code
... which seemed to work OK. So you could try that. Two possible issues for us to look at ... 1. Does proposeType propose DICTIONARY? Should it in the case where the proposed record name (in this case "0") is not valid Genero syntax? 2. Should DICTIONARY OF DYNAMIC ARRAY OF ... be valid syntax? Reuben Title: Re: JSON Return Post by: Gary C. on May 14, 2018, 09:27:07 am Hi Reuben
I was not aware of the proposeType method so thanks for that as it will come in very handy. Your workaround of using a type has worked perfectly so again, thanks for the suggestion. Gary Title: Re: JSON Return Post by: Reuben B. on May 22, 2018, 02:14:45 am ... Two possible issues for us to look at ... 1. Does proposeType propose DICTIONARY? Should it in the case where the proposed record name (in this case "0") is not valid Genero syntax? 2. Should DICTIONARY OF DYNAMIC ARRAY OF ... be valid syntax? Reuben I left two hanging questions which I will wrap up... 1. Does proposeType propose DICTIONARY? Should it in the case where the proposed record name (in this case "0") is not valid Genero syntax? It won't. With the proposeType method, view the result as a starting point for you to refine, don't expect the result to be a 100% solution. It maybe that you need to replace a RECORD with DICTIONARY, or it maybe that you need to utilise the json_name attribute http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_json_utils_names.html to map a JSON element name to a 4gl record element name. 2. Should DICTIONARY OF DYNAMIC ARRAY OF ... be valid syntax? Short answer is it should, for the moment the work around is to use TYPE. We'd consider the better practise would be to use TYPE in any event. More interesting points to note. In general the compiler with ... DEFINE var-name collation-type OF element-type should not limit element-type to non-collation type So any combination of collation-type and lengths of combinations could be allowed, without having to resort to types. (the lengths being interesting, DEFINE ddd DICTIONARY OF DICTIONARY OF DICTIONARY ... might be useful for sparse data ...) Reuben |