简体   繁体   中英

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?

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

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

Working example

使用JSON.stringify(dataArray)它用于保持括号

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM