views:

46

answers:

2

At the server end (GAE), I've got a java Hashtable.

At the client end (iPhone), I'm trying to create an NSDictionary.

myHashTable.toString() gets me something that looks darned-close-to-but-not-quite-the-same-as [myDictionary description]. If they were the same, I could write the string to a file and do:

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:tmpFile];

I could write a little parser in obj-C to deal with myHashtable.toString(), but I'm sort-of hoping that there's a shortcut already built into something, somewhere -- I just can't seem to find it.

(So, being a geek, I'll spend far longer searching the web for a shortcut than it would take me to write & debug the parser... ;)

Anyway -- hints?

Thanks!

+5  A: 

I would convert the Hashtable into something JSON-like and take it on the iPhone side.

Hashtable.toString() is not ideal, it will have problem with spaces, comma and quotation marks.

For JSON-to-NSDictionary, you can find the json-framework tools under http://www.json.org/

J-16 SDiZ
Yeah, it turns out that "convert to json, convert back at the other end" was the answer. Took longer to download the json source than to actually implement the "how-to" code.Cool beans -- thanks! :)
Olie
+1  A: 

As j-16 SDiZ mentioned, you need to serialize your hashtable. It can be to json, xml or some other format. Once serialized, you need to deserialize them into an NSDictionary. JSON is probably the easiest format to do this with plenty of libraries for both Objective-C and Java. http://json.org has a list of libraries.

Elfred
J-16 had the right answer first, but vote-up for the list of libraries. Thanks!(I'm new to json, but it appears pretty cool, and it's binary brother, bson, too!)
Olie