[RESOLVED] parseJSON Returning Wrong Type-VBForums
Results 1 to 2 of 2

Thread: [RESOLVED] parseJSON Returning Wrong Type

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,156

    Resolved [RESOLVED] parseJSON Returning Wrong Type

    I'm attempting to load the following literal into a JSON object, but when I call typeof on the variable it says that it is an object rather than an array. Can you spot what could be causing this:
    Code:
    var data = $.parseJSON('[{"Type":"Boat","Name":"Merle Gonsoulin","Official_Number":"1270118","Length":78,"Breadth":34,"Depth":10,"Gross_Tons":222,"HP":2000,"Engine":"Cummins KTA38M2","Built":2016,"Status":"Standby"},{"Type":"Barge","Name":"Gonsoulin 546","Official_Number":"1263066","Length":297.5,"Width":54,"Depth":12,"BBL":30000,"Built":2015,"Status":"Standby"},{"Type":"Barge","Name":"Gonsoulin 528","Official_Number":"1240327","Length":297.5,"Width":54,"Depth":12,"BBL":30000,"Built":2015,"Status":"Standby"}]');
    Here is the JSON uncompacted:
    Code:
    [
      {
        "Type": "Boat",
        "Name": "Merle Gonsoulin",
        "Official Number": "1270118",
        "Length": 78,
        "Breadth": 34,
        "Depth": 10,
        "Gross Tons": 222,
        "HP": 2000,
        "Engine": "Cummins KTA38M2",
        "Built": 2016,
        "Status": "Standby"
      },
      {
        "Type": "Barge",
        "Name": "Gonsoulin 546",
        "Official Number": "1263066",
        "Length": 297.5,
        "Width": 54,
        "Depth": 12,
        "BBL": 30000,
        "Built": 2015,
        "Status": "Standby"
      },
      {
        "Type": "Barge",
        "Name": "Gonsoulin 528",
        "Official Number": "1240327",
        "Length": 297.5,
        "Width": 54,
        "Depth": 12,
        "BBL": 30000,
        "Built": 2015,
        "Status": "Standby"
      }
    ]

  2. #2

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,156

    Re: parseJSON Returning Wrong Type

    For those of you wondering, it is because an array in JavaScript is an object. To determine if it is truly an array, I used the Array.isArray method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.