json > minus, colon, plus character key problem

M

Marc

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... :/
 
S

scripts.contact

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']);
 
M

Marc

scripts.contact said:
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!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top