2017-08-05 56 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它的調試變量你可以刪除它 –