JQuery JSON string versus PHP json_encode?

Are used to create a simple array where {} creates an "object" used like an associative array in this case.

Are used to create a simple array where {} creates an "object" used like an associative array in this case. The first example assign the value 33 to the index 0, but you can use anything as an index. In the second example, you're creating a number indexed array.

2 Javascript does not have associative arrays. The first one is an object. – Lightness Races in Orbit Apr 5 '11 at 15:33 @Tomalak strictly speaking, you can't call it an object also.

But object is probably better than hashmap or associative array. – krtek Apr 5 '11 at 15:35 Why not? That's what it is.

– Lightness Races in Orbit Apr 5 '11 at 15:37.

{"0":"33"} This is a literal that represents an Object with one element, whose key is "0" and whose answer is "33". "News"," world news"," latest news" This is a literal that represents an Array with three elements, whose values are plain to see in the code. JQuery has nothing to do with it.

This is Javascript syntax, which is why JSON stands for JavaScript Object Notation.

The first one is an associative array (key-value pair, 0 is the key, 33 is the value). The second example is a list with 3 positions. They have both been "stringified" with JSON but are different data structures.

1 Javascript does not have associative arrays. The first one is an object. – Lightness Races in Orbit Apr 5 '11 at 15:32 From wikipedia: An associative array (also associative container, map, mapping, dictionary, finite map, and in query-processing an index or index file) is an abstract data type composed of a collection of unique keys and a collection of values.

Even if it's not the official Javascript name, it is, data-structure wise, an associative array. – tiagoboldt Apr 5 '11 at 15:43 But that definition doesn't strictly map to Javascript Objects. Objects sort of emulate the concept of associative arrays, but they are not the same.

– Lightness Races in Orbit Apr 5 '11 at 15:47 @Tomalak, do point me some references (even if JS internals) for me to learn where they differ :) – tiagoboldt Apr 5 '11 at 16:04 Actually I take it back; I still think of Objects in Javascript as far more than associative arrays, but having looked around I can see why you might call them that. – Lightness Races in Orbit Apr 5 '11 at 16:13.

As said above, the difference in json is: is array, accepts only value { } is object, accepts both key and value They can be composited together as below: var contact = { "Name": "John Doe", "PermissionToCall": true, "PhoneNumbers": { "Location": "Home", "Number": "555-555-1234" }, { "Location": "Work", "Number": "555-555-9999 Ext. 123" } }; so next time you can figure out how to compose it yourself :D.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions