skip to Main Content

Kind of new (inexperienced) to JSON. I’m trying to add an accessorial code in my project. Example codes is "HAZ".

I’ve created a public class for Accessorials (see below) and in that class I have "Public codes As String()".

Public Class Accessorials
    Public codes As String()
    Public hazardousContact As HazardousContact
    Public cod As Object
    Public insuranceDetails As Object
    Public sortAndSegregateDetails As Object
    Public markDetails As Object
End Class

Which in turn feeds the primary Wrapper

Public Class fgtload 'Primary wrapper
    Public service As New fgtservice
    Public payment As New fgtpayment
    Public transit As New fgttransit
    Public commodities As New List(Of Items)
    Public origin As New fgtorigin
    Public destination As New fgtdestination
    Public billTo As New fgtbillto
    **Public accessorials As New Accessorials**
End Class

I’m trying to add the code "HAZ" to the class Accessorials.
which shows the code as " Public codes As String()"
I’m assuming by the () that it’s looking for an array of sorts.
Should (within the primary wrapper) accessorials be a List(Of Accessorials) ?

The outcome should be :

"accessorials" : {
    "codes" : [ "HAZ" ],
    "hazardousContact" : {
    "name" : "John Snow",
    "phone" : "7704865900"
},

Here’s the full JSON from the API Guide

{"service":{"level":"STND"},"payment":{"terms":"Prepaid","payer":"Shipper"},"transit":{"pickupDate":"20230930"},"commodities":[{"classification":"92.5","weight":"1500","length":"48","width":"40","height":"40","pieces":"3","packagingType":"PAT","description":"Umbrellas","stackable":"Y"},{"classification":"50","weight":"50","length":"48","width":"48","height":"48","pieces":"5","packagingType":"PAT","description":"Soda","stackable":"N"}],"accessorials":{"codes":["HAZ"],"hazardousContact":{"name":"John Snow","phone":"7704865900"},"cod":null,"insuranceDetails":null,"sortAndSegregateDetails":null,"markDetails":null},"origin":{"account":"1234567","city":"LEBANON","stateProvince":"TN","postalCode":"37090","country":"USA"},"destination":{"account":"","city":"Calgary","stateProvince":"AB","postalCode":"T1Y2S2","country":"CAN"},"billTo":{"account":"","name":"Bill To Company","address":"456 Bill Me Rd.","city":"LEBANON","stateProvince":"TN","postalCode":"37090","country":"USA"}}

2

Answers


  1. Chosen as BEST ANSWER

    The resolution was:

    Load.accessorials.codes = New List(Of String) Load.accessorials.codes.Add("IDL") -Or use this Load.accessorials.codes = New List(Of String)({"IDL"})

    Also seems the code I was actually using, from the actual API Guide ,was invalid, i.e. a typo. I've contacted their web support and reported the typo. Once I started using the correct code I was able to process the JSON without error.

    I found that the code was bad by further consuming the httpresponse using :

      Dim sReader = New StreamReader(webExcp.Response.GetResponseStream)
            Dim result = sReader.ReadToEnd
            result = result
    

    By doing so I saw the error about the submitted code being invalid. I wasn't aware of the capability of consuming a greater error code as such. I normally just snagged the stats and simple message. Live and learn. Anyway I'm good now. Thanks for all your inputs.


  2. Not sure why the following wouldn’t work?

    Dim f = new fgtload
    ReDim Preserve f.accessorials.codes(f.accessorials.codes.Length)
    f.accessorials.codes(f.accessorials.codes.Length - 1) = "HAZ"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search