CS Lewis
CS Lewis

Reputation: 489

How to keep the square brackets in place when I extract data from JSON?

All:

We are using NEwtonsoft JSON.NET to serialize some C# POCOs, and we get the following:

{

    "RouteID": "123321213312",
    "DriverName": "JohnDoe",
    "Shift": "Night",
     "ItineraryCoordinates": [
        [ 9393, 4443 ],
        [ 8832, 3322 ],
        [ 223, 3432 ],
        [ 223, 3432 ]
    ]           
}

In an AJAX jQuery function, I have the following:

 alert($.parseJSON(data.d).ItineraryCoordinates);

Sadly, the result in the popup alert box is:

  9393, 4443 , 8832, 3322, 223, 3432, 223, 3432

Could someone please tell me how I can implement the code in such a way that the square brackets are kept in place?

Upvotes: 0

Views: 72

Answers (2)

Tanmay
Tanmay

Reputation: 590

use JSON.stringify(dataArray) it is used keep the brackets

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337560

You can use JSON.stringify to achieve what you require:

var data = $.parseJSON(data.d);
alert(JSON.stringify(data.ItineraryCoordinates));

Working example

Upvotes: 3

Related Questions