Hi,
When I post json objects from jquery
$.ajax({
type: 'POST',
url: '/url',
dataType: 'json',
data: {"key":"val","hash",{"foo":"bar"}}
then the "hash" parameter is posted like this: "hash[foo]=bar"
If I then in hunchentoot have
(define-easy-handler (fn :uri "/url")
((hash :parameter-type 'hash-table))
.....
The hash is expected to be posted like this: "hash{foo}=bar"?
So I wonder if it would be correct to enable the "hash[foo]=bar" syntax for hash tables.
Maybe it should be an argument that specifies if compute-hash-table-parameter should use [] or {}.
This little experiment worked for me, here I just added \\[ and \\] to the regexp.
Should I bother to make a patch?
(defun compute-hash-table-parameter (parameter-name type parameters key-type test-function)
"Retrieves all parameters from PARAMETERS which are named like
\"PARAMETER-NAME{FOO}\" or \"PARAMETER-NAME[FOO]\" \(where FOO is any sequence of characters
not containing curly brackets), converts them to TYPE, and
returns a hash table with test function TEST-FUNCTION where the
corresponding value is associated with the key FOO \(converted to
KEY-TYPE)."
(let ((hash-table (make-hash-table :test test-function)))
(loop for (full-name . value) in parameters
for key = (register-groups-bind (name key-string)
("^(.*)[{\\[]([^\\[\\]{}]+)[}\\]]$" full-name)
(when (string= name parameter-name)
(convert-parameter key-string key-type)))
when key
do (setf (gethash key hash-table)
(convert-parameter value type)))
hash-table))
--
Knut Olav Bøhmer