how to handle JavaScript objects with colons in key names?

Posted by Ethan on Stack Overflow See other posts from Stack Overflow or by Ethan
Published on 2010-06-05T19:07:30Z Indexed on 2010/06/05 19:12 UTC
Read the original article Hit count: 154

Filed under:
|

There is a syntax error in the following code:

<!DOCTYPE html>
<html>
  <body>
    Hello World!
    <script type="text/javascript">
        var obj = {'a:b': '1'};
        alert(obj.a:b); // syntax error
    </script>
  </body>
</html>

So how to handle JavaScript objects with colons in key names?

I have to do this because I need to handle a feed in jsonp format from a remote server which I do not have control over, and there are colons in the key names of the returned jsonp (because the jsonp is converted from XML with namespaces in tags).

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about JSON