I'm in the process of integrating with a shipping webservice.
The JSON I get in the response looks like this:
{"poMasterIds":[],"errorMap":{"0":["Unit weight for POLine 0 is null"]},"isSuccess":false,"errorCode":601}
So I have a little program to try to interpret it. I used util.JSON.proposeType and it said to use this:
RECORD
poMasterIds DYNAMIC ARRAY OF STRING,
errorMap RECORD
0 DYNAMIC ARRAY OF STRING
END RECORD,
isSuccess BOOLEAN,
errorCode FLOAT
END RECORD
So I did that and this is my little program:
IMPORT util
SCHEMA fms
#
MAIN
DEFINE
result_json STRING # Resulting JSON
#
#-------Data structure for JSON
#
DEFINE pt_response RECORD
poMasterIds DYNAMIC ARRAY OF STRING,
errorMap RECORD
dummy DYNAMIC ARRAY OF STRING ATTRIBUTES (json_name="0")
END RECORD,
isSuccess BOOLEAN,
errorCode INTEGER
END RECORD
DEFINE i,j INTEGER
LET result_json = '{"poMasterIds":[],"errorMap":{"0":["Unit weight for POLine 0 is null"]},"isSuccess":false,"errorCode":601}'
DISPLAY util.JSON.proposeType(result_json)
CALL util.JSON.parse(result_json,pt_response)
DISPLAY "poMasterIds:"
LET i = pt_response.poMasterIDs.getLength()
FOR j = 1 TO i
DISPLAY pt_response.poMasterIds[j]
END FOR
DISPLAY "errorMap:"
LET i = pt_response.errorMap.dummy.getLength()
DISPLAY "dummy length",i
FOR j = 1 TO i
DISPLAY pt_response.errorMap.dummy[j]
END FOR
DISPLAY "isSuccess ",pt_response.isSuccess
DISPLAY "errorCode ",pt_response.errorCode
END MAIN
Here is my output from DISPLAY statements:
RECORD
poMasterIds DYNAMIC ARRAY OF STRING,
errorMap RECORD
0 DYNAMIC ARRAY OF STRING
END RECORD,
isSuccess BOOLEAN,
errorCode FLOAT
END RECORD
poMasterIds:
errorMap:
dummy length 0
isSuccess 0
errorCode 601
So I'm unable to display
["Unit weight for POLine 0 is null"]So I think I have something wrong in my structure.
Does anyone have any ideas?
Thanks!
Candy