Javascript – How to convert a JSON string to a JavaScript object in jQuery

javascriptjqueryjson

I have a string in my db I want to pull into my page and convert to a JavaScript object.

[
{id: 1,title: "Long Event",
       start: new Date(2009, 5, 6, 14, 0),end: new Date(2009, 5, 11)},
{id: 2,title: "Repeating Event",
       start: new Date(2009, 5, 2)},
{id: 3,title: "Meeting",
       start: new Date(2009, 5, 20, 9, 0)},
{id: 4,title: "Click for Facebook",
       start: new Date(2009, 5, 27, 16),end: new Date(2009, 5, 29),
       url: "http://facebook.com/"}
]

How can I do this using jQuery?

Best Solution

As of jQuery 1.4.1 you can do this natively

jQuery.parseJSON

See jQuery documentation.