Xcode NSData to Json returns null


NSData *urlDatat = [NSData dataWithContentsOfURL: [NSURL URLWithString:stringURL]];
NSDictionary* json1 = [NSJSONSerialization JSONObjectWithData:urlDatat options:0 error:&error];
NSString *urlDataString =[[NSString alloc] initWithData:urlDatat encoding:NSUTF8StringEncoding];
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:urlDatat options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments|NSJSONReadingMutableLeaves  error:&error];

json1json都返回 null。来自服务器的实际 JSON 数据={"statusCode":"1","message":"success","utcMilliSeconds":"1501953923847"}

尝试使用

NSDictionary *responseData = [NSJSONSerialization JSONObjectWithData:urlDatat options:NSJSONReadingMutableLeaves error:&error];

更新

NSURL *url = [NSURL URLWithString:@"https://api.kidstriangle.com/KTStandaloneAPI/Common/GetUtcMilliSeconds"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

最新更新