Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > json > minus, colon, plus character key problem

Reply
Thread Tools

json > minus, colon, plus character key problem

 
 
Marc
Guest
Posts: n/a
 
      04-30-2007
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... :/


 
Reply With Quote
 
 
 
 
scripts.contact
Guest
Posts: n/a
 
      04-30-2007
On Apr 30, 1:44 am, "Marc" <(E-Mail Removed)> 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']);

 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      04-30-2007
"scripts.contact" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Apr 30, 1:44 am, "Marc" <(E-Mail Removed)> 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!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lib to generate XML/JSON[P] output from a DTD/XSD/JSON Schema/etc Acácio Centeno Python 1 02-15-2013 07:34 AM
I am facing an issue while decoding json string using json.loads sajuptpm Python 2 12-28-2012 07:16 AM
[ANN] Security Fix json-1.1.7 for json_pure and json gems Florian Frank Ruby 0 06-30-2009 05:18 PM
"JSON for ASP" at json.org Tuğrul Topuz ASP General 1 06-27-2008 11:37 PM
C plus plus vs C Sharp The LoxFather C++ 23 08-14-2003 03:51 AM



Advertisments