freebase + obj-c: error 256
I'm trying to fetch data from freebase using obj-c and I can't get it working:
NSError* error;
NSString* jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://ap开发者_如何学运维i.freebase.com/api/service/mqlread?query={\"query\":[{\"guid\":\"% 9202a8c04000641f80000000000052be\"}]}"] encoding:NSASCIIStringEncoding error:&error];
The URL is fine (I've checked by hand in my browser) but jsonString is nil and error is:
Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x4e4de80 {}
Is there something wrong with encoding? I have replaced the # in the URL with %23.
Make sure you don't have spaces in your url - the guid value has a space in it. Use %20 to encode the spaces.
Also, the ideal identifier to use with Freebase is a 'mid' (ask for 'mid' : null in your query).
精彩评论