iosiphone開(kāi)發(fā)入門(mén)教程源碼和10云端應(yīng)用_第1頁(yè)
iosiphone開(kāi)發(fā)入門(mén)教程源碼和10云端應(yīng)用_第2頁(yè)
iosiphone開(kāi)發(fā)入門(mén)教程源碼和10云端應(yīng)用_第3頁(yè)
iosiphone開(kāi)發(fā)入門(mén)教程源碼和10云端應(yīng)用_第4頁(yè)
iosiphone開(kāi)發(fā)入門(mén)教程源碼和10云端應(yīng)用_第5頁(yè)
已閱讀5頁(yè),還剩30頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

主要知識(shí)GETXMLJSONPOSTGET請(qǐng)?<?xmlversion="1.0"<product<?xmlversion="1.0"<product 點(diǎn)擊按-(IBAction)onClickButton:(id)sender//NSString*str=[[NSStringalloc] o.NSString*strURL=[NSString",NSURL*url=[NSURLNSURLRequest*request=[[NSURLRequestalloc]initWithURL:url];NSURLConnection*connection=[[NSURLConnectionalloc][connectionrelease];[requestrelease];[activityIndicatorstartAnimating];}解定義NSURLConnection的委托?NSURLRequest*request=[[NSURLRequestalloc]initWithURL:url];?NSURLConnection*connection=[[NSURLConnectionalloc] ?委托(delegate)是一種 NSURLConnection回調(diào)方?-(void)connection:(NSURLConnection*)connectiondidReceiveData:(NSData*)data?-(void)connection:(NSURLConnection*)connectiondidFailWithError:(NSError*)error?-(void)(NSURLConnection*)加載數(shù)據(jù)成功,在connection:didReceiveData方法之接收數(shù)據(jù)處//upateData=[[NSDataalloc]NSStringEncodingenc=NSString*gbkNSString=[[NSStringalloc]initWithData:dataencoding://如果是非UTF-8NSXMLParser會(huì)報(bào)錯(cuò)xmlString=[[NSStringalloc] cingOccurrencesOfString:@"<?xmlversion=\"1.0\"encoding=\"gbk\"?>"withString:@"<?xmlversion=\"1.0\"encoding=\"utf-8\"?>"]];[gbkNSStringrelease];}解 XML解?關(guān) NSURLConnection在眾多的回調(diào)方法。解析XMLconnectionDidFinishLoading:方法開(kāi)始解析XML文件也是要通過(guò)XML?NSXMLParser,是 解析XMLSDK工具類(lèi)。 解析開(kāi)始處[activityIndicator//開(kāi)始解析NSXMLParser*ipParser=[[NSXMLParseralloc][ipParserparse];[ipParserrelease];}NSXMLParser回調(diào)方?- :(NSXMLParser?-(void)parser:(NSXMLParser*)parserparseErrorOccurred:(NSError*)parseError?(void)parser:(NSXMLParser*)parserdidStar (NSString*)elementNamenamespaceURI:(NSString*)namespaceURIqualifiedName:(NSString*)qualifiedNameattributes:(NSDictionary*)attributeDict?遇到一個(gè)開(kāi) NSXMLParser回調(diào)方?-(void)parser:(NSXMLParser*)parserfoundCharacters:(NSString*)string?-(void)parser:(NSXMLParser*)parserdidEndElement:(NSString*)elementNamenamespaceURI:(NSString*)namespaceURIqualifiedName:(NSString*)qName?遇到結(jié) ?- :(NSXMLParser文檔開(kāi)始的回調(diào)方這個(gè)方法在解析過(guò)程中只調(diào)運(yùn)一次,一般在這個(gè)--:(NSXMLParser*)parser infoinfo=[[NSMutableDictionaryinitWithCapacity:}}文檔出錯(cuò)回調(diào)方--(void)parser:(NSXMLParser*)parserparseErrorOccurred:(NSError*)parseError{UIAlertView*errorAlert=[[UIAlertViewinitWithTitle:[parseErrormessage:[parseError[errorAlertshow];[errorAlertrelease];}遇到開(kāi) 回調(diào)方?參數(shù)elementName是 是屬性列表,namespaceURI是命名空間,如果-(void)parser:(NSXMLParser*)parser qualifiedName:(NSString*)qualifiedNameattributes:(NSDictionary*)attributeDict{NSLog(@"value:%@\n",elementName);currentTagName=elementName;}遇到字符串回調(diào)方-(void)parser:(NSXMLParser*)parserfoundCharacters:(NSString*)stringNSLog(@"value:%@\n",string=[stringstringByRe if([currentTagNameisEqualToString:@"ip"]){[infosetValue:stringforKey:}}elseif([currentTagNameisEqualToString:@"location"]){if(![stringisEqualToString:@""]){[infosetValue:stringforKey:}}}遇到結(jié) 回調(diào)方--(void)parser:(NSXMLParser*)parserdidEndElement:(NSString*)elementNamenamespaceURI:(NSString*)namespaceURIqualifiedName:(NSString*)qName{}-:(NSXMLParser*)parserNSMutableString*outstring-:(NSXMLParser*)parserNSMutableString*outstring=[[NSMutableStringalloc]initWithCapacity:for(idkeyininfo)}updateView.text=[outstring[xmlString}JSON解JSON解???{s e=eytf??s??sn.e??ersrel;e=JSON解析?ek?e實(shí)現(xiàn)回調(diào)方?-(void)connection:(NSURLConnection*)connectiondidReceiveData:(NSData*)data?-(void)connectionDidFinishLoading:(NSURLConnection*)connection?-(void)connection:(NSURLConnection*)connectiondidFailWithError:(NSError*)error--(void)connection:(NSURLConnection*)connectiondidReceiveData:(NSData*)data{outString=[[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding];NSLog(@"%@",}?outString的JSONValue消息獲得NSMutableDictionary,JSONapi中提供了NSString的分類(lèi)(Ca -(void)connectionDidFinishLoading:(NSURLConnection*)connection{[activityIndicatorViewstopAnimating];NSMutableDictionary*jsonoObj=[outStringNSLog(@"%@",NSMutableDictionary*jsonoSubObj=[jsonoObjNSString*text=[[NSStringalloc]textView.text=text;[textrelease];[outString}文檔出錯(cuò)回調(diào)方--(void)parser:(NSXMLParser*)parserparseErrorOccurred:(NSError*)parseError{UIAlertView*errorAlert=[[UIAlertViewinitWithTitle:[parseErrormessage:[parseError[errorAlertshow];[errorAlertrelease];}點(diǎn)擊按-{NSString*strurl= lat=43&lng=-NSURL*url=[NSURLNSURLRequest*request=[[NSURLRequestalloc]initWithURL:url];NSURLConnection*connection=[[NSURLConnectionalloc]initWithRequest:requestdelegate:self];[connectionrelease];[request[activityIndicatorView}POST請(qǐng)??POST請(qǐng)求與GET不同,不使用的txtUserName.text,txtPwd.text];NSData*postData=[postNSURL*webServiceURL=[NSURL "];[requestif(!connection)NSLog(@"Failedtosubmit}else}}解POST參數(shù)是以一個(gè)字符串方式傳遞:?[request知道請(qǐng)求方法為POST方法,但是要注意POST[requestsetHTTPBody:postData];該語(yǔ)句是將 (void)connection:(NSURLConnection*)connectiondidReceiveData:(NSData*){resultString=[[NSStringalloc]}-(void)connectionDidFinishLoading:(NSURLConnection*)theConnectionNSStringif([resultStringisEqual:@"1"])messageNSStringallocinitWithFormat:@"%@@"}else}

messageNSStringallocinitWithFormat:@"%@@"UIAlertView*alert=[[UIAlertView:message:message[alert[alertrelease];[re

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論