title: hashing a Java JSONObject
body: <p>I'm currently writing a jsonrpc-client in java. A request is represented by an <a href="http://www.json.org/javadoc/org/json/JSONObject.html" rel="nofollow">JSONObject</a> like this:</p>
  
  <pre><code>{'method': 'do.stuff', 'params': ['asdf', 3, {'foo': 'bar'}]}
  </code></pre>
  
  <p>Now I want to implement a low-level request cache and for this I need a way to create a hash from a JSONObject that will always return the same value. Using the toString() is not an option since JSONObjects are unordered: the following example would do exactly the same as my first example even though the string representation is different:</p>
  
  <pre><code>{'params': ['asdf', 3, {'foo': 'bar'}], 'method': 'do.stuff'}
  </code></pre>
  
  <p>Whats the best solution to this problem? The jsonobject may be nested to any arbitrary depth of course. I'm fairly new to Java and thankful for any suggestion.</p>