In Javascript, JSON objects (well, JS objects in general) have a great short hand little way of accessing values using the fullstop object notation.
In other words, using a JSON dataset looking like:
{“status”:”1″,”message-data”:”Success!”}
we could access the “status” value by simply entering:
alert(myobject.status);
However, if we tried the same thing with the “message-data” key, you will note that this will fall over syntactically straight away – all because of that silly hyphen (dash).
So the way around this?
Well you basically have to revert to the long notation format to get at the data associated with these keys, meaning that you would now need to do something like this:
alert(myobject["message-data"]);
And now you know.
Nifty.
Related Posts :
Here is a particularly simple and short validation check to ensure that a value received is in f ...
A simple way to calculate how many days are in a month in Javascript is to leverage Javascript's ...
Thanks to Twitter, the idea of accessible, useful, and more importantly, simple web services has ...
Anchor names are a great little browser extra that allows you to quickly jump to different secti ...
To stop a MySQL server instance on an Ubuntu linux install via the command line is as simple as ...






