我有一個給出路徑的字符串,另一個給它附加參數。當我把它們放入一個字符串並顯示時,我的格式正確。如果我嘗試將整個字符串放入NSURL中,它將顯示NULL。 獲取它的格式是什麼?來自字符串的URL給出null
NSString *booking=urlForBooking.bookHall;
NSLog(@" book %@",booking); // this prints --- http://10.2.0.76:8080/ConferenceHall/BookingHallServlet
NSString *bookingString=[booking stringByAppendingString:[NSString stringWithFormat:@"? employeeId=%@&conferenceHallId=%@&bookingId=%d&purpouse=%@&fromDate=%@&toDate=%@&comments=%@&submit=1",empId,_hallId,_bookingId,_purpose,fromDateStr,toDateStr,_comments]];
NSLog(@"book str %@",bookingString); //this prints --- ?employeeId=3306&conferenceHallId=112&bookingId=0&purpouse=S&fromDate=25/Feb/2013 13:29&toDate=25/Feb/2013 15:29&comments=C&submit=1
NSURL *bookingURL=[NSURL URLWithString:bookingString];
NSLog(@"BOOK %@",bookingURL); //here I'm not getting the url(combined string), it gives null.
您的NSLog()輸出與代碼不一致。如果'bookingString'由'booking'通過*追加*來完成,那麼'bookingString'應該以'「http://10.2.0.76:....」開始。這是你的實際代碼嗎? – 2013-02-11 09:48:15