allen58992008 / touchcode

Automatically exported from code.google.com/p/touchcode
0 stars 0 forks source link

CJSONDeserializer deserializeAsArray: does not skip whitespace #72

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using TouchJSON 1.0.7 Release:

    NSError *error = nil;
    NSData *json = [NSData dataWithBytes:" [ 123 ]" length:8]; // first character is a whitespace
    NSArray *array = [[CJSONDeserializer deserializer] deserializeAsArray:json error:&error];
    NSLog(@"array: %@ error:%@", array, error);

Expected:
array: (
    123
) error:(null)

Actual:
array: (null) error:Error Domain=CJSONScannerErrorDomain Code=-7 
UserInfo=0x3d1d4b0 "Could not scan array. Array not started by a 
'{' character."

Also, the error description should be "Array not started by a '[' character." 
instead of "Array not started by a '{' character."

Workaround:
Using deserialize: instead of deserializeAsArray:

Note:
The same problem probably applies to deserializeAsDictionary: as well.

Original issue reported on code.google.com by cedric.l...@gmail.com on 13 Jan 2010 at 3:24

GoogleCodeExporter commented 8 years ago
Many thanks for filing this.

The problem is that the stripping of the whitespace generally occurs before 
(and after obviously) those methods 
are performed. To perform them again inside the method would incur a (slight) 
performance hit for the general 
case.

That said I think you do have a valid bug and will think about a solution.

Original comment by jwight on 13 Jan 2010 at 3:31

GoogleCodeExporter commented 8 years ago
Maybe the easiest solution is to remove deserializeAsDictionary:error: and 
deserializeAsArray:error: from the  CJSONDeserializer header. All the 
deserialize methods return id anyway…

Original comment by cedric.l...@gmail.com on 4 Jun 2010 at 2:10

GoogleCodeExporter commented 8 years ago
Fixed in latest github.

Original comment by jwight on 1 Nov 2010 at 7:31