(Objective-C) Using JSON StringOf with Non-String Members
If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.
#import <CkoJsonObject.h>
#import <NSString.h>
// Create JSON with members of different data types.
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateInt: @"a" value: [NSNumber numberWithInt: 123]];
[json UpdateBool: @"b" value: YES];
[json UpdateNull: @"c"];
json.EmitCompact = NO;
NSLog(@"%@",[json Emit]);
// Resulting JSON:
// {
// "a": 123,
// "b": true,
// "c": null
// }
NSString *a = [json StringOf: @"a"];
NSLog(@"%@",a);
NSString *b = [json StringOf: @"b"];
NSLog(@"%@",b);
NSString *c = [json StringOf: @"c"];
NSLog(@"%@",c);
// Output
// 123
// true
// null
// If you want to get the integer, boolean, or null value
// you need to use the methods matching the data type
int ival = [[json IntOf: @"a"] intValue];
BOOL bval = [json BoolOf: @"b"];
BOOL hasNull = [json IsNullOf: @"c"];
|