json_encode equivalent for objective-c

后端 未结 1 1627
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 22:53

I need to write the equivalent to this php code

json_encode(utf8_encode())

in objective-c

I\'ve implemented the equivalent to utf8

相关标签:
1条回答
  • 2021-01-15 23:20

    You could have a look at

    + (NSData *)dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error
    

    You get back JSON data from some object of Apples Foundation classes. If you need a string, you could use:

    - (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding
    

    of NSString. Might result in something like:

    NSString *string = [[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:YOUR_OBJECT_HERE options:0 error:nil] encoding:NSUTF8StringEncoding] autorelease];
    
    0 讨论(0)
提交回复
热议问题