URL 和JSON和 plist小結

2021-07-27 17:25:31 字數 1711 閱讀 5894

#import "url.h"

@inte***ce url ()

@property(nonatomic,strong) uiwebview *webview;

@end

@implementation url

/* nsurlrequestuseprotocolcachepolicy = 0, 預設快取

nsurlrequestreloadignoringlocalcachedata = 1, 忽略本地快取直接載入伺服器資料

nsurlrequestreturncachedataelseload = 2, 先走快取資料,然後走伺服器資料

nsurlrequestreturncachedatadontload = 3, 返回快取資料沒如果沒有快取就空著

//cachepolicy 快取策略 timeoutinterval請求超時時長

nsurlrequest *request1 = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreturncachedataelseload timeoutinterval:15.0];

// nsblockoperation *q = [nsblockoperation blockoperationwithblock:^];

nsoperationqueue *aa = [[nsoperationqueue alloc]init];//如果是aa就是非同步 如果是[nsthread currentthread];就是主線程
// [aa addoperation:q];

/*

nsurlresponse

url 伺服器返回的url 大部分一樣有時候會不一樣「重定向」

mimetype 二進位制檔案型別 伺服器會告訴客戶端可以用什麼軟體開啟

textencodingname 文字編碼名稱,大多是utf8

suggestedfilename 伺服器建議儲存的檔名稱

statuscode 狀態碼 2xx 3xx 重定向 4xx客戶端錯誤 5xx伺服器錯誤

allheaderfields 所以響應頭的內容

data: 資料內容 就是要展示的資料

connectionerror:如果沒錯錯誤也沒有資料 應該是網路錯誤

*///傳送網路請求

[nsurlconnection sendasynchronousrequest:request queue:aa completionhandler:^(nsurlresponse * _nullable response, nsdata * _nullable data, nserror * _nullable connectionerror)

}];nsdata* data = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil];

nslog(@"%@",data);

nslog(@"ssss");

[nsurlsession sharedsession];

-(void)plistdemo];@end

JSON和plist的序列化和反序列化

nsdata data nsdata alloc init nsdictionary dic nsdictionary dictionary nsjsonserialization jsonobjectwithdata dataoptions nsjsonreadingmutablecontaine...

讀取和寫入plist檔案

plist檔案是標準的xml檔案,在cocoa中可以很簡單地使用。這裡介紹一下使用方法 以下 在mac和iphone中均適用。寫入plist檔案 nsmutabledictionary dict nsmutabledictionary alloc initwithcontentsoffile sam...

plist檔案的讀取和使用

nsbundle mainbundle pathforresource sysmessagering oftype plist plistpath 2 可以通過filemanager獲取該目錄下的所有檔案,來檢視獲取目錄是否正確 nsfilemanagerdefaultmanager content...