Hello Everyone,
I have been having a heck of a time trying to decode the JSON code below.
I am trying process the vessel calls in the ReadDataNew function below. When trying to process the data JSON at the end of this message, I get a BOUND error.
I hoping someone can shread some light on the best way to process this data.
Thank you in advance for your assistance!
//-----------------------------------------------------------------------------
static function ReadVessel( hJson )
local aData := {}
local aRow, aCalls, hCall
local d, n, i, j, aDt
local ARRI, DEPA
local cPol, cPolName, cDateTim, dEtd, cEtdTime, cStr
aCalls := hJson[ "vessel" ]
AADD( aData, { "IMO" , aCalls["vesselIMONumber"] } )
AADD( aData, { "VESSEL" , aCalls["vesselName"] } )
AADD( aData, { "FLAG" , aCalls["vesselFlagCode"] } )
AADD( aData, { "CALLSIGN", aCalls["vesselCallSign"] } )
AADD( aData, { "VCODE" , aCalls["carrierVesselCode"] } )
return aData
//-----------------------------------------------------------------------------
static function ReadDataNew( hJson )
local aData := {}
local aRow, aCalls, hCall
local d, n, i, j, aDt
local ARRI, DEPA
local cPol, cPolName, cDateTim, dEtd, cEtdTime
local lPass := .T., cPass
aCalls := hJson[ "vesselCalls" ]
aEval( aCalls, { |h| hb_HSetCaseMatch( h, .f. ) } )
for n := 1 to Len( aCalls )
lPass := .T.
hCall := aCalls[ n ]
if hCall[ "callSchedules" ][ 1 ][ "transportEventTypeCode" ] == "DEPA"
DEPA := 1
ARRI := 2
else
ARRI := 1
DEPA := 2
endif
if n == 1
cPol := hCall[ "facility" ][ "UNLocationCode" ]
cPolName := hCall[ "facility" ][ "portName" ]
cDateTim := hCall[ "callSchedules" ][ DEPA ][ "classifierDateTime" ]
else
if (hCall[ "facility" ][ "UNLocationCode" ] == cPol)
if ( d := hCall[ "callSchedules" ][ DEPA ][ "classifierDateTime" ] ) > cDateTim
cDateTim := d
endif
else
if dEtd == nil .AND. (cDateTim <> nil)
aDt := ParseDateTime( cDateTim )
dEtd := aDt[ 1 ]
cEtdTime := aDt[ 2 ]
endif
aRow := Array( 12 )
aRow[ FLD_VESSEL ] := hJson[ "vessel" ][ "vesselName" ]
aRow[ FLD_VOYAGE ] := hCall[ "transport" ][ "outboundService" ][ "carrierVoyageNumber" ]
aRow[ FLD_LLOYDS ] := hJson[ "vessel" ][ "vesselIMONumber" ]
aRow[ FLD_POL ] := cPol
aRow[ FLD_POLNAME ] := cPolName
aRow[ FLD_ETD ] := DTOC(dEtd)
aRow[ FLD_ETDTIME ] := cEtdTime
aRow[ FLD_POUL ] := hCall[ "facility" ][ "UNLocationCode" ]
aRow[ FLD_POULNAME ] := hCall[ "facility" ][ "portName" ]
aDt := ParseDateTime( hCall[ "callSchedules" ][ ARRI ][ "classifierDateTime" ] )
aRow[ FLD_ETA ] := DTOC(aDt[ 1 ])
aRow[ FLD_ETATIME ] := aDt[ 2 ]
aRow[ FLD_SERVICE ] := hCall[ "transport" ][ "outboundService" ][ "carrierServiceCode" ]
AAdd( aData, aRow )
endif
endif
next
return aData
//-----------------------------------------------------------------------------
static function ParseDateTime( cDateTime )
local dDate, cTime
cTime := SubStr( cDateTime, 12, 8 )
dDate := STOD( StrTran( Left( cDateTime, 10 ), "-", "" ) )
return { dDate, cTime }
/*** JSON below
{"vessel":{"vesselIMONumber":"9332999","carrierVesselCode":"Q4F","vesselName":"MAERSK DENVER","vesselFlagCode":"US","vesselCallSign":"WMDQ"},"vesselCalls":[{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-03-21T20:30:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-03-22T11:30:00"}],"facility":{"locationType":"TERMINAL","locationName":"Salalah Terminal","carrierTerminalCode":"OMSLVTM","carrierTerminalGeoID":"2LU3R3RRU5RVI","countryCode":"OM","countryName":"Oman","cityName":"Salalah","portName":"Salalah","carrierCityGeoID":"30ECXPXBQJMHO","UNLocationCode":"OMSLL"},"transport":{"inboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-03-25T06:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-03-26T02:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Jebel Ali Terminal 2","carrierTerminalCode":"AEJALT2","carrierTerminalGeoID":"035ZCENG0J317","countryCode":"AE","countryName":"United Arab Emirates","cityName":"Jebel Ali","portName":"Jebel Ali","carrierCityGeoID":"31RTK5H2BLBS3","UNLocationCode":"AEJEA"},"transport":{"inboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-03-28T09:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-03-29T11:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Port Qasim Terminal","carrierTerminalCode":"PKPQ1TM","carrierTerminalGeoID":"2P6HZUCGKJ42M","countryCode":"PK","countryName":"Pakistan","cityName":"Port Qasim","portName":"Port Qasim","carrierCityGeoID":"3FQ5D7WV73R3S","UNLocationCode":"PKQCT"},"transport":{"inboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-03-31T04:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-03-31T22:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Pipavav Terminal","carrierTerminalCode":"INPPVTM","carrierTerminalGeoID":"1CGC6GKQ02IGW","countryCode":"IN","countryName":"India","cityName":"Pipavav","portName":"Pipavav","carrierCityGeoID":"1QF1SC3MCQHUZ","UNLocationCode":"INPPV","UNRegionCode":"GJ"},"transport":{"inboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-04-02T04:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-04-03T07:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Jawaharlal Nehru NSICT DPW","carrierTerminalCode":"INJHTTM","carrierTerminalGeoID":"20JWFD10UBY3H","countryCode":"IN","countryName":"India","cityName":"Jawaharlal Nehru","portName":"Jawaharlal Nehru","carrierCityGeoID":"20JS07ETK8AE1","UNLocationCode":"INNSA","UNRegionCode":"MH"},"transport":{"inboundService":{"carrierVoyageNumber":"306E","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-04-05T23:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-04-06T15:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Salalah Terminal","carrierTerminalCode":"OMSLVTM","carrierTerminalGeoID":"2LU3R3RRU5RVI","countryCode":"OM","countryName":"Oman","cityName":"Salalah","portName":"Salalah","carrierCityGeoID":"30ECXPXBQJMHO","UNLocationCode":"OMSLL"},"transport":{"inboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-04-10T23:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-04-11T15:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Canal Zone Terminal","carrierTerminalCode":"EGSUCCN","carrierTerminalGeoID":"3792U3SWTPXA8","countryCode":"EG","countryName":"Egypt","cityName":"Suez Canal","portName":"Suez Canal","carrierCityGeoID":"0DOPTVWPU73B2"},"transport":{"inboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}},{"callSchedules":[{"transportEventTypeCode":"ARRI","eventClassifierCode":"EST","classifierDateTime":"2023-04-15T20:00:00"},{"transportEventTypeCode":"DEPA","eventClassifierCode":"EST","classifierDateTime":"2023-04-16T14:00:00"}],"facility":{"locationType":"TERMINAL","locationName":"Algeciras - ML Terminal","carrierTerminalCode":"ESALRTM","carrierTerminalGeoID":"0NTE1JGVL9NBT","countryCode":"ES","countryName":"Spain","cityName":"Algeciras","portName":"Algeciras","carrierCityGeoID":"05R47F3DBN69Q","UNLocationCode":"ESALG"},"transport":{"inboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"},"outboundService":{"carrierVoyageNumber":"312W","carrierServiceCode":"600","carrierServiceName":"MECL"}}}]}