2017-08-05 75 views
-1
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"}Xcode NSData返回null

+1

有没有在'error'参数的任何输出? – vadian

+0

使用'error'参数。另外,是'urlDatat'零? – Larme

+0

您如何知道“来自服务器的实际JSON数据”?你打印了吗?你打印了urlDataString吗?或者你是否在浏览器中输入了URL,并假设你会得到? – gnasher729

回答

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]; 
+1

我曾试过仍然没有运气。这里是我的服务器地址:http://api.kidstriangle.com/KTStandaloneAPI/Common/GetUtcMilliSeconds –

+0

看看编译后的代码更新 –

+0

NSString * responseString它的调试变量你可以删除它 –