tags:

views:

65

answers:

3

I am learning JSON, but I found out that you can put what are called "hashes" into JSON as well? Where can I find out what a hash is? Or could you explain to me what a hash is? Also, what's a hashmap? I have experience in C++ and C#, and I am learning JS, Jquery, and JSON.

+2  A: 

Hash = dictionary.

A hash:

{ "key1": "value1", "key2": "value2" }
Daniel Straight
+2  A: 

Here's an excellent article on hash tables, i.e. hash maps

Boris Pavlović
helpful article, thanks!
Alex
+1  A: 

Hey Alex.

I hope I'm understanding your question correctly.

A Hash is an array that uses arbitrary strings/objects (depending on the implementation, this varies across programming languages) rather than plain integers as keys.

In Javascript, any Object is technically a hash (also referred to as a Dictionary, Associative-Array, etc).

Examples:

 var myObj = {}; // Same as = new Object();
  myObj['foo'] = 'bar';

  var myArr = []; // Same as = new Array();
  myArr[0] = 'foo';
  myArr[1] = 'bar';
  myArr['blah'] = 'baz'; // Error, arrays cannot take strings as keys, only objects can, under JS.

Now, since JSON is basically using JS constructs and some strict guidelines to define portable data, the equivalent to myObj above would be:

{ "foo" : "bar" };

Hope this helps.

Lior Cohen
wow that's it? I was overcomplicating things.
Alex