Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / April 2007



Tip: Looking for answers? Try searching our database.

json > minus, colon, plus character key problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc - 30 Apr 2007 08:44 GMT
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... :/
scripts.contact - 30 Apr 2007 09:01 GMT
> 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']);
Marc - 30 Apr 2007 09:43 GMT
>> 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!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.