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];
json1
和json
都返回null。来自服务器的实际JSON数据为={"statusCode":"1","message":"success","utcMilliSeconds":"1501953923847"}
答案 0 :(得分:0)
尝试使用
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];