Skip to content

Instantly share code, notes, and snippets.

@kambala-decapitator
Created February 16, 2021 17:11
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 kambala-decapitator/94adb76c6849ddee2dc41c8fd6e05930 to your computer and use it in GitHub Desktop.
Save kambala-decapitator/94adb76c6849ddee2dc41c8fd6e05930 to your computer and use it in GitHub Desktop.
simple test of JSON decoding in ObjC
#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