An NSURL object represents a URL that can potentially contain the location of a resource on a remote server, the path of a local file on disk, or even an arbitrary piece of encoded data. 指明获取数据的对象 网站地址 或者文件地址等
NSURLRequest objects represent a URL load request in a manner independent of protocol and URL scheme.创建一个请求,可以指定缓存策略以及超时时间。
The NSURLConnection
class provides convenience class methods to load URL requests both asynchronously using a callback block and synchronously.连接成功则返回数据
-
start:开始下载。默认初始化设定了delegate后便自动开始,但如果没有设定则可以调用此开始
- cancel:在一次请求开始到结束之间调用cancel,会结束当前的请求,并不再接受消息。
- connection :didReceiveResponse:当接受了足够创建NSURLResponse对象的数据后会调用。
- connection:didReceiveData:下载开始后,每当有数据包,都会定期的调用此方法,我们应该在该方法里存储接受到的数据。
- connection:didFailWithError:下载过程中有异常,返回失败信息后便不再接收数据
- connectionDidFinishLoadi
ng:下载顺利完成。
For greater control, you can create a URL connection object with a delegate object that conforms to the NSURLConnectionDelegate
andNSURLConnectionDataDelegate
protocols. The connection calls methods on that delegate to provide you with progress and status as the URL request is loaded asynchronously. The connection also calls delegate methods to let you override the connection’s default behavior (for example, specifying how a particular redirect should be handled). These delegate methods are called on the thread that initiated the asynchronous load operation.
NSJSONSerialization
NSJSONReadingOptions
Options used when creating Foundation objects from JSON data—see JSONObjectWithData:options:error:
and JSONObjectWithStream:options:error:
.
enum { NSJSONReadingMutableContainers = (1UL << 0), NSJSONReadingMutableLeaves = (1UL << 1), NSJSONReadingAllowFragments = (1UL << 2) }; typedef NSUInteger NSJSONReadingOptions;
Constants
-
Specifies that arrays and dictionaries are created as mutable objects.// 应该是最灵活的 所有对象都可以
Available in iOS 5.0 and later.
Declared in
NSJSONSerialization.h
. -
Specifies that leaf strings in the JSON object graph are created as instances of
NSMutableString
.//可变字符串对象Available in iOS 5.0 and later.
Declared in
NSJSONSerialization.h
. -
Specifies that the parser should allow top-level objects that are not an instance of
NSArray
orNSDictionary
.//不能是不可变的对象Available in iOS 5.0 and later.
Declared in
NSJSONSerialization.h
.
NSJSONReadingMutableContainers
NSJSONReadingMutableLeaves
NSJSONReadingAllowFragments