On Tue, 04 Dec 2007 14:45:17 -0800, pbd22 wrote:
[snip of some sample code]
OK, thanks.
SO, how do handle special case characters in my JSON strings?
I have keys such as "The Last Mermain (1994) - Limited Edition".
I agree with you, escape really messes things up. But, the
special characters are causing all sorts of probs with JSON
syntax.
Please help... deadline.
THanks.
Chances are, with that key like that, you have a design issue. I can't
see your code, so I'm not 100% certain -- but I strongly suggest you
look things over and go "Why?"
That said, if you are totally sure you want to do this, there might
be a better way to get what you are after. (Even with the best CRC
method there is still a (very small) chance collisions. Reading up
on hash tables and how to handle collisions isn't a bad idea.)
Checksums, like a CRC checksum.
http://www.digsys.se/js_crc.html
var key = "'some (annoying) text'";
var keyhash = crc(key);
alert("Keyhash = " + keyhash); // 0x4DE4C95E
var MyObj = {}
MyObj[keyhash] = "friendly text";
If anything of value is lost by hashing the key -- if in the running of
your program changing 'some (annoying) text' to 0x4DE4C95E matters --
then you have a bad key/value design.
good:
var book = {"title": "The Last Mermain (1994) - Limited Edition",
"pages" : 8008};
Bad:
var badbook = {"How to Win Friends and Influence People": "book",
{"details" : "80 pages."}
};