TouchCode / TouchJSON

A humane JSON Objective-C un-framework. (TouchJSON has been deprecated - see README)
http://touchcode.com/
Other
800 stars 169 forks source link

Deserialization does not work for me #16

Closed jlebright closed 12 years ago

jlebright commented 13 years ago

Here is my json: { "siteinfo": [ { "title": "My Title", "address": "My Addres", "phone1": "(559) 426-4444", "welcomeMessage": "msg", "mainLogoUrl": "data:image/png;base64, iVBORw0KG..." } ] }

Of course I truncated the base64 data since it is rather large.

Here is my objective c code: //This was my first attempt, it gave me an error in CJSONScanner.m (theData.Length was null!!!) //NSData theJSONData = jsonResult; //NSError theError = nil; //id theObject = [[CJSONDeserializer deserializer] deserialize:theJSONData error:&theError];

//This is my second attempt:

NSString *jsonString = jsonResult;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];

In this case no error and data.length equals zero in CJSONScanner.m (which seems wrong) an I cannot see anything in dictionary -print dictionary gives me the following:

(gdb) print *dictionary $1 = {

= { isa = 0xe4880c }, } I have verified my json works fine with a javascript library I use so I am at a loss here. I am suspecting I am misusing your library ??? Thanks for any help in advance, Joe Ebright
schwa commented 12 years ago

Sorry for the delay responding. I do not get email for these bug reports.

I just tested your JSON here:

NSError *theError = NULL;
NSString *theString = @"{ \

\"siteinfo\": [ \ { \ \"title\": \"My Title\", \ \"address\": \"My Addres\", \ \"phone1\": \"(559) 426-4444\", \ \"welcomeMessage\": \"msg\", \ \"mainLogoUrl\": \"data:image/png;base64, iVBORw0KG...\" \ } \ ] \ }"; NSData theData = [theString dataUsingEncoding:NSUTF8StringEncoding]; // NSData theData = [@"\"\u062a\u062d\u064a\u0627 \u0645\u0635\u0631!\"" dataUsingEncoding:NSUTF8StringEncoding]; theString = [[CJSONDeserializer deserializer] deserialize:theData error:&theError]; theData = [[CJSONSerializer serializer] serializeObject:theString error:&theError]; theString = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@"%@", theString);

Everything worked as expected.

2011-11-02 08:18:49.172 TouchJSON Demo[29837:707] {"siteinfo":[{"phone1":"(559) 426-4444","welcomeMessage":"msg","title":"My Title","mainLogoUrl":"data:image/png;base64, iVBORw0KG...","address":"My Addres"}]}

You can use various web based JSON lint tools if you think your JSON is badly formatted.

If you still have a problem re-open this bug.