summaryrefslogtreecommitdiffstats
path: root/macosx/NSJSONSerialization+HBAdditions.m
blob: 0f18eb17c8f2d749f9b02409705bf428ed4e6698 (plain)
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
/*  NSJSONSerialization+HBAdditions.m $

 This file is part of the HandBrake source code.
 Homepage: <http://handbrake.fr/>.
 It may be used under the terms of the GNU General Public License. */

#import "NSJSONSerialization+HBAdditions.h"

@implementation NSJSONSerialization (HBAdditions)

+ (id)HB_JSONObjectWithUTF8String:(const char *)nullTerminatedCString options:(NSJSONReadingOptions)opt error:(NSError **)error;
{
    NSData *data = [NSData dataWithBytes:nullTerminatedCString length:strlen(nullTerminatedCString)];
    id result = [NSJSONSerialization JSONObjectWithData:data options:opt error:error];
    return result;
}

+ (NSString *)HB_StringWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error
{
    NSData *data = [NSJSONSerialization dataWithJSONObject:obj options:opt error:error];
    if (data)
    {
        return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    }

    return nil;
}

@end