My favorites | Sign in
Project Home
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 52 attachment: CJSONSerializer_Issue52.patch (1.3 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
diff -r ab6ba0207ff6 TouchJSON/Source/JSON/CJSONSerializer.m
--- a/TouchJSON/Source/JSON/CJSONSerializer.m
+++ b/TouchJSON/Source/JSON/CJSONSerializer.m
@@ -154,10 +154,11 @@

NSEnumerator *theEnumerator = [inArray objectEnumerator];
id theValue = NULL;
+NSUInteger i = 0;
while ((theValue = [theEnumerator nextObject]) != NULL)
{
[theString appendString:[self serializeObject:theValue]];
- if (theValue != [inArray lastObject])
+ if (++i < [inArray count])
[theString appendString:@","];
}
return([NSString stringWithFormat:@"[%@]", theString]);
diff -r ab6ba0207ff6 TouchJSON/UnitTests/CJSONSerializer_UnitTests.m
--- a/TouchJSON/UnitTests/CJSONSerializer_UnitTests.m
+++ b/TouchJSON/UnitTests/CJSONSerializer_UnitTests.m
@@ -45,4 +45,14 @@
id theObject = [[CJSONSerializer serializer] serializeObject:dictionary];
STAssertEqualObjects(jsonEquivalent, theObject, nil);
}
+
+/* http://code.google.com/p/touchcode/issues/detail?id=52 */
+-(void)test_SerializeArrayWithDuplicatedInstances {
+ NSString *a = @"a";
+ NSArray *input = [NSArray arrayWithObjects:a, @"b", a, nil];
+ NSString *expected = @"[\"a\",\"b\",\"a\"]";
+ id output = [[CJSONSerializer serializer] serializeObject:input];
+ STAssertEqualObjects(expected, output, nil);
+}
+
@end
Powered by Google Project Hosting