Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created August 20, 2014 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/25859aa59308c4eff9bb to your computer and use it in GitHub Desktop.
Save danielgomezrico/25859aa59308c4eff9bb to your computer and use it in GitHub Desktop.
Category to get a string from an array of JSONModel objects using JSONModel 1.0.1
#import "JSONModel.h"
@interface NSArray (CRNSArrayJSON)
- (NSString*)toJSONString;
@end
#import "NSArray+JSON.h"
@implementation NSArray (CRNSArrayJSON)
-(NSString*) toJSONString
{
// src=http://stackoverflow.com/a/18219972/273119
NSMutableArray* jsonObjects = [NSMutableArray new];
for ( id obj in self )
{
[jsonObjects addObject:[obj toJSONString]];
}
return [NSString stringWithFormat:@"[%@]",
[jsonObjects componentsJoinedByString:@","]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment