JSON name/value name as number

D

Dominic

Hi there,

I'm looking to transfer some data between functions and I thought I'd use
json such that the notation will be like this:

var myJSONThing = {12:34, 345:32, 987:345...}.

function myFunction(myJSONThing){
....
}

Now I looked and the name/value pair should, according to the documentation
I could find, have the name enclosed with "s yet the script I'm writing
seems to be working (at least in Firefox). Is it totally necessary to have
the quotation marks or just good practice? Also, would it have an effect on
iterating through the object? I guess the answer to the first of my
questions is the important thing as I don't want it to break in the future.

Cheers,

Dom
 
T

Thomas 'PointedEars' Lahn

Dominic said:
I'm looking to transfer some data between functions and I thought I'd use
json such that the notation will be like this:

var myJSONThing = {12:34, 345:32, 987:345...}.

That is _not_ JSON.
function myFunction(myJSONThing){
...
}

Now I looked and the name/value pair should, according to the
documentation I could find, have the name enclosed with "s yet

It MUST if it is supposed to be JSON.
the script I'm writing seems to be working (at least in Firefox). Is it
totally necessary to have the quotation marks or just good practice?

It is only necessary if you want JSON. You want to learn what JSON is, and
what an ECMAScript-conforming (e.g., JavaScript) Object initializer/literal
is instead:

<http://json.org/>
<http://jibbering.com/faq/#posting>


PointedEars
 
G

Garrett Smith

D

Dominic

Garrett Smith said:
Dominic wrote:
[...]

It is only necessary if you want JSON. You want to learn what JSON is,
and
what an ECMAScript-conforming (e.g., JavaScript) Object
initializer/literal
is instead:

<http://json.org/>
<http://jibbering.com/faq/#posting>

Also check out Hallvords JSON test suite.

http://my.opera.com/core/blog/2009/12/18/native-json-support-in-opera

very informative at a glance -- you can easily see what fails and then go
directly to the source code.

Garrett

Thank you both. As I was unclear I asked here and I got the answer I
expected, my script is now changed. Though I initially was creating the JSON
object by evaluating a string that I made I then changed and created it as a
native object once I was happy with using JSON ;-)

Dom
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top