Created
February 16, 2021 17:11
-
-
Save kambala-decapitator/94adb76c6849ddee2dc41c8fd6e05930 to your computer and use it in GitHub Desktop.
simple test of JSON decoding in ObjC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) | |
{ | |
if (argc != 2) | |
{ | |
printf("pass JSON in a single argument\n"); | |
return 1; | |
} | |
__auto_type json = argv[1]; | |
__auto_type data = [NSData dataWithBytesNoCopy:json length:strlen(json)]; | |
NSError *err = nil; | |
id obj = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&err]; | |
NSLog(@"%@", obj ?: err); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment