How do I parse this invalid JSON string in jQuery?

Posted by LesterDove on Stack Overflow See other posts from Stack Overflow or by LesterDove
Published on 2010-05-20T15:35:33Z Indexed on 2010/05/20 15:40 UTC
Read the original article Hit count: 234

Filed under:
|
|

Hi, I am looking to access the various bits of data in this data attribute:

<div class="location" data="{id: 4, point: {lng: -71.413364, lat: 41.673681}, category: 'Restaurant'}">

The data attribute is easy enough to reach in jQuery, of course. But the string seems to be a non-standard or invalid form of JSON. I've tried JSON.parse() and also a basic JS method of splitting the array. By all accounts, it just seems to be an invalidly-serialized string.

Will I need to reformat the data string? (it doesn't come from me, and it's used by other routines that I'd rather not break, so...)

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON