That may very well have been the problem. Whatever it was, after I had fixed some other bugs, the json_encode function produced strings for hashes that worked perfectly well with the API. As is often the case, the problem was user error.
-----Original Message-----
From: Code for Libraries on behalf of Posthumus, Etienne
Sent: Fri 6/6/2008 12:56 AM
To: [log in to unmask]
Subject: Re: [CODE4LIB] Open Library API
David wrote:
>The problem is that for the two programming languages I use, Java and
> PHP the variable name key~ and $key~ is illegal, and I believe that is
> the case for most programming languages. Thus, in this PHP class (an its
> Java analog) would fail at compile / parse time:
<snip>
> Note that
> $query = json_encode(array('key~'=>'\/about\/*'));
> will not be parsed through the API, and results in an error message.
Hi David
In the PHP example that you gave, try changing it to:
$query = json_encode(array('key~'=>'/about/*'));
The slashes in that string gets escaped by the JSON ecoder. If you already escape them before encoding, it gets double-escaped to look like this:
{"key~":"\\\/about\\\/*"}
That is probably why you got an error message from the API.
I don't think that this is an issue in almost all programming languages. The point is that you don't want to name any variables 'key~' but this is just a string key in an associative array (or HashMap or dict whatever your programming language calls it).
regards,
Etienne Posthumus
TU Delft Library
Email Disclaimer: http://www.co.marin.ca.us/nav/misc/EmailDisclaimer.cfm
|