json > minus, colon, plus character key problem

Discussion in 'Javascript' started by Marc, Apr 30, 2007.

  1. Marc

    Marc Guest

    I took a sample json string from: http://www.json.org/example.html

    {"web-app": {
    "servlet": [
    {
    "servlet-name": "cofaxCDS",
    "servlet-class": "org.cofax.cds.CDSServlet",
    "init-param": { etc...
    And parse that creating a html treeview, if I try and get a value:
    alert(json.web-app.servlet[0].servlet-name);
    the minus in 'web-app' is giving problems.

    The toJSONString and parseJSON functions I'm using found on the same site do
    not escape the key's
    http://www.json.org/json.js

    This must be a no brainer but I've been staring at this problem for so long
    I just don't see a solution... :/
     
    Marc, Apr 30, 2007
    #1
    1. Advertising

  2. On Apr 30, 1:44 am, "Marc" <> wrote:
    > if I try and get a value:
    > alert(json.web-app.servlet[0].servlet-name);
    > the minus in 'web-app' is giving problems.


    alert(json['web-app'].servlet[0]['servlet-name']);
     
    scripts.contact, Apr 30, 2007
    #2
    1. Advertising

  3. Marc

    Marc Guest

    "scripts.contact" <> wrote in message
    news:...
    > On Apr 30, 1:44 am, "Marc" <> wrote:
    >> if I try and get a value:
    >> alert(json.web-app.servlet[0].servlet-name);
    >> the minus in 'web-app' is giving problems.

    >
    > alert(json['web-app'].servlet[0]['servlet-name']);
    >


    Oooohhhh... if was sooo... close! Thx a lot!!
     
    Marc, Apr 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,369
  2. claude uq
    Replies:
    5
    Views:
    375
    Phlip
    Dec 17, 2003
  3. dorayme
    Replies:
    6
    Views:
    1,825
    dorayme
    Jun 27, 2010
  4. RobG
    Replies:
    6
    Views:
    250
  5. Replies:
    0
    Views:
    129
Loading...

Share This Page