-
Sep 25th, 2017, 10:57 PM
#1
[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"
}
]
-
Sep 27th, 2017, 04:00 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|