通过大众点评平台开发来简单了解一下,oc的网络编程和数据解析(json)

首先我们需要到大大众点评开发者平台申请一个key。http://developer.dianping.com/app/tech/api这个网站有api文档。

本文没有使用第三方库,网络其请求使用NSURLConnection类,json数据解析使用NSJSONSerialization。这个例子是根据条件获取商户信息。

1.定义常量

#define kSearchResto @"v1/business/find_businesses"

#define kDPDomain @"http://api.dianping.com/"

#define kDPAppKey @"。。。"

#define kDPAppSecret @"。。。"

#define kWFRequestimeOutInterval 60.0

#define kHttpMethodGET @"GET"

#define kHttpMethodPOST @"POST"

2.创建数据类,包含商户信息

//
// WFBusiness.h
// WFSearch
//
// Created by ForrestWoo on 14-9-5.
// Copyright (c) 2014年 ForrestWoo. All rights reserved.
// #import <Foundation/Foundation.h> #import "WFRootModel.h" @interface WFBusiness : WFRootModel @property (nonatomic, assign) int business_id;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *branch_name;
@property (nonatomic, strong) NSString *address;
@property (nonatomic, strong) NSString *telephone;
@property (nonatomic, strong) NSString *city;
//星级图片链接。
@property (nonatomic, strong) NSString *rating_img_url;
@property (nonatomic, strong) NSString *rating_s_img_url;
@property (nonatomic, strong) NSArray *regions;
@property (nonatomic, strong) NSArray *categories; //经纬度信息
@property (nonatomic, assign) float latitude;
@property (nonatomic, assign) float longitude;
@property (nonatomic, assign) float avg_rating;
@property (nonatomic, assign) float product_score;
@property (nonatomic, assign) float decoration_score;
@property (nonatomic, assign) float service_score; //评价 分五种。1:一般,2:尚可,3:好,4:很好,5:非常好
@property (nonatomic, assign) int product_grade;
@property (nonatomic, assign) int decoration_grade;
@property (nonatomic, assign) int service_grade; //人均消费。
@property (nonatomic, assign) int avg_price;
//点评。
@property (nonatomic, assign) int review_count;
@property (nonatomic, strong) NSArray *review_list_url;
@property (nonatomic, assign) int distance;
@property (nonatomic, strong) NSString *business_url; //图片
@property (nonatomic, strong) NSString *photo_url;
@property (nonatomic, strong) NSString *s_photo_url;
@property (nonatomic, assign) int photo_count;
@property (nonatomic, strong) NSArray *photo_list_url; //优惠券。
@property (nonatomic, assign) int has_coupon;
@property (nonatomic, assign) int coupon_id;
@property (nonatomic, strong) NSString *coupon_description;
@property (nonatomic, strong) NSString *coupon_url; //团购信息。
@property (nonatomic, assign) int has_deal;
@property (nonatomic, assign) int deal_count;
@property (nonatomic, strong) NSArray *deals;
@property (nonatomic, strong) NSString *deals_id;
@property (nonatomic, strong) NSString *deals_description;
@property (nonatomic, strong) NSString *deals_url;
@property (nonatomic, assign) int has_online_reservation;
@property (nonatomic, strong) NSString *online_reservation_url; - (id)initWithJson:(NSDictionary *)jsonData; @end

这里的属性名字并不是随便定义的,而是根据服务器端返回的字段名称定义的,它与返回的名称是一致的,目的是方便以后通过反射对类的属性赋值,这样我们不需要一一赋值,详情请继续

3.WFRootModel

#import <Foundation/Foundation.h>

//根类,定义一些通用的属性和消息
@interface WFRootModel : NSObject //获取类的属性名称,以通过反射对对象的属性赋值。
- (NSArray *)PropertyKeys; @end #import "WFRootModel.h"
#import <objc/runtime.h> @implementation WFRootModel - (NSArray *)PropertyKeys
{
unsigned int outCount,i;
objc_property_t *pp = class_copyPropertyList([self class], &outCount);
NSMutableArray *keys = [[NSMutableArray alloc] initWithCapacity:0];
for (i = 0; i < outCount; i++)
{
objc_property_t property = pp[i];
NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
[keys addObject:propertyName];
} return keys;
} @end

  此类赋予了它的子类一个重要行为,它只包含一个消息[- (NSArray *)PropertyKeys],它的作用是子类能够获取自己包含的所有属性。反射中会使用这些属性。

4.创建请求url

  大众点评请求使用SHA加密。

[1]SHA加密类SHA1,需要引入

CommonDigest.h
@interface SHA1 : NSObject

+ (NSString *)getSHAString:(NSData *)aStringbytes;

@end

#import <CommonCrypto/CommonDigest.h>

#import "SHA1.h"

@implementation SHA1

+ (NSString *)getSHAString:(NSData *)aStringbytes
{
unsigned char digest[CC_SHA1_DIGEST_LENGTH]; if (CC_SHA1([aStringbytes bytes], [aStringbytes length], digest))
{
NSMutableString *digestString = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
{
unsigned char aChar = digest[i];
[digestString appendFormat:@"%02x",aChar];
}
return digestString;
}
else
{
return nil;
}
} @end

由于我对加密了解很少,所以就不做介绍了,只给出一个方法,供大家参考。

[2]返回根url,因为根url会常用到,我们就将它封装起来,以便后用

- (NSString *)getRootURL
{
return kDPDomain;
}

[3]返回合法的url

- (NSString *)serializeURL:(NSString *)aBaseURL params:(NSDictionary *)aParams
{
NSURL* parsedURL = [NSURL URLWithString:[aBaseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithDictionary:[self parseQueryString:[parsedURL query]]];
if (aParams) {
[paramsDic setValuesForKeysWithDictionary:aParams];
} NSMutableString *signString = [NSMutableString stringWithString:kDPAppKey];
NSMutableString *paramsString = [NSMutableString stringWithFormat:@"appkey=%@", kDPAppKey];
NSArray *sortedKeys = [[paramsDic allKeys] sortedArrayUsingSelector: @selector(compare:)];
for (NSString *key in sortedKeys) {
[signString appendFormat:@"%@%@", key, [paramsDic objectForKey:key]];
[paramsString appendFormat:@"&%@=%@", key, [paramsDic objectForKey:key]];
}
NSString *str = kDPAppSecret;
[signString appendString:str];
NSData *stringBytes = [signString dataUsingEncoding: NSUTF8StringEncoding];
NSString *digestString = [SHA1 getSHAString:stringBytes];
if (digestString)
{
[paramsString appendFormat:@"&sign=%@", [digestString uppercaseString]];
NSLog(@"...%@...", [NSString stringWithFormat:@"%@://%@%@?%@", [parsedURL scheme], [parsedURL host], [parsedURL path], [paramsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]);
return [NSString stringWithFormat:@"%@://%@%@?%@", [parsedURL scheme], [parsedURL host], [parsedURL path], [paramsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
else
{
return nil;
}
}

5.创建网络连接,发送请求

使用NSURLConnection来完成网络连接

- (void)createConnectionWithUrl:(NSString *)urlString params:(NSDictionary *)aParams delegate:(id<WFRequestDelegate>)aDelegate
{
NSString *urlStr = [self serializeURL:[self generateFullURL:urlString] params:aParams];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:kWFRequestimeOutInterval]; [request setHTTPMethod:kHttpMethodGET];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
self.delegate = aDelegate;
// [[[self class] sharedInstance] setConnections:conn];
}

6.返回结果以及数据解析

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
_responseData = [[NSMutableData alloc] init];
} - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_responseData appendData:data];
} - (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error = nil;
id result= [NSJSONSerialization JSONObjectWithData:_responseData options:NSJSONReadingAllowFragments error:&error];
if (!result)
{
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:error,@"error", nil];
NSError *err = [NSError errorWithDomain:@"domain is error" code:-1 userInfo:userInfo];
if ([self.delegate respondsToSelector:@selector(request:didfailWithError:)])
{
[self.delegate request:self didfailWithError:err];
}
}
else
{
NSString *status = 0;
if ([result isKindOfClass:[NSDictionary class]])
{
status = [result objectForKey:@"status"];
} if ([status isEqualToString:@"OK"])
{
if ([self.delegate respondsToSelector:@selector(request:didfinishloadingWithResult:)])
{
[self.delegate request:self didfinishloadingWithResult:result == nil ?
_responseData : result];
}
}
else
{
if ([status isEqualToString:@"ERROR"])
{
//TODO:错误处理代码。
}
}
} // NSString *str = [[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
// NSLog(@"_responseData:%@", str); // [self clearData];
} - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR!%@", error.description);
}

返回的数据存储在一个WFFindBusinessesResult的实例中。

//super class for result.
@interface WFUrlResult : NSObject @property (nonatomic, strong) NSString *status;
@property (nonatomic, assign) NSInteger total_count;
@property (nonatomic, assign) NSInteger count; - (id)initWithJson:(NSDictionary *)jsonData; @end @interface WFFindBusinessesResult : WFUrlResult @property (nonatomic, strong) NSArray *businesses; @end

对对象赋值非常简单

@implementation WFFindBusinessesResult

- (id)initWithJson:(NSDictionary *)jsonData
{ self.status = [jsonData objectForKey:@"status"];
self.count = [[jsonData objectForKey:@"count"] integerValue];
self.total_count = [[jsonData objectForKey:@"total_count"] integerValue];
NSArray *arr = nil;
NSMutableArray *businessArr = [[NSMutableArray alloc] initWithCapacity:0]; if ([jsonData isKindOfClass:[NSDictionary class]])
{
arr = [jsonData objectForKey:@"businesses"];
    //赋值,通过反射赋值,根本不需要一一对字段赋值。
for (id obj in arr)
{
WFBusiness *bus = [[WFBusiness alloc] init];
NSArray *propertyList = [[[WFBusiness alloc] init] PropertyKeys];
for (NSString *key in propertyList)
{ [bus setValue:[obj objectForKey:key] forKey:key];
}
[businessArr addObject:bus];
NSLog(@"photo is %@", [bus categories]);
} }
NSLog(@"businessArr count is %lu", [businessArr count]);
self.Businesses = businessArr;
return self;
} @end

完整的封装类WFHTTPRequest。它用于创建一个连接,并发送请求,管理整个应用出现的网络连接,创建一个单例,全局唯一。

//
// WFRequest.h
// WFSearch
//
// Created by ForrestWoo on 14-8-30.
// Copyright (c) 2014年 ForrestWoo. All rights reserved.
// #import <Foundation/Foundation.h> @class WFHTTPRequest;
@protocol WFRequestDelegate <NSObject> @optional
- (void)request:(WFHTTPRequest *)request didfinishloadingWithResult:(id)aResult;
- (void)request:(WFHTTPRequest *)request didfailWithError:(NSError *)aError; @end @interface WFHTTPRequest : NSObject @property (nonatomic, unsafe_unretained) id<WFRequestDelegate> delegate;
@property (nonatomic, strong) NSString *aUrl;
@property (nonatomic, strong) NSDictionary *aParams;
@property (nonatomic, strong) NSArray *connections; + (WFHTTPRequest *)sharedInstance; - (void)createConnectionWithUrl:(NSString *)urlString params:(NSDictionary *)aParams delegate:(id<WFRequestDelegate>)aDelegate; - (void) cancel;
- (NSString *)getRootURL; //api - (void)findBusinessesWithParams:(NSDictionary *)aParams delegate:(id<WFRequestDelegate>)aDelegate;
- (void)findCityWithDelegate:(id<WFRequestDelegate>)aDelegate;
- (void)getCategoriesForBusinessesWithDelegate:(id<WFRequestDelegate>)aDelegate; @end
//
// WFRequest.m
// WFSearch
//
// Created by ForrestWoo on 14-8-30.
// Copyright (c) 2014年 ForrestWoo. All rights reserved.
// #import "WFHTTPRequest.h"
#import "WFConstants.h"
#import "SHA1.h" @interface WFHTTPRequest () <NSURLConnectionDataDelegate> //- (void)appendUTF8Body:(NSMutableData *)aBody dataString:(NSString *)aDataString;
//- (NSDictionary *)parseQueryString:(NSString *)query;
////- (void)handleResponseData:(NSData *)data;
//- (NSString *)generateFullURL:(NSString *)url;
////- (void)addConnection;
//- (NSString *)serializeURL:(NSString *)aBaseURL params:(NSDictionary *)aParams; @end static WFHTTPRequest *sharedObj = nil; @implementation WFHTTPRequest
{
NSURLConnection *_connection;
NSMutableData *_responseData;
} - (NSString *)getRootURL
{
return kDPDomain;
} - (NSString *)generateFullURL:(NSString *)url
{
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:0]; [str appendString:[self getRootURL]];
[str appendString:url];
return str;
} + (WFHTTPRequest *)sharedInstance
{
static dispatch_once_t pred = 0; dispatch_once(&pred, ^{
sharedObj = [[super allocWithZone:NULL] init];
}); return sharedObj;
} + (id)allocWithZone:(struct _NSZone *)zone
{
return [self sharedInstance];
} - (void)createConnectionWithUrl:(NSString *)urlString params:(NSDictionary *)aParams delegate:(id<WFRequestDelegate>)aDelegate
{
NSString *urlStr = [self serializeURL:[self generateFullURL:urlString] params:aParams];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:kWFRequestimeOutInterval]; [request setHTTPMethod:kHttpMethodGET];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
self.delegate = aDelegate;
// [[[self class] sharedInstance] setConnections:conn];
} - (void)findBusinessesWithParams:(NSDictionary *)aParams delegate:(id<WFRequestDelegate>)aDelegate
{
[self createConnectionWithUrl:kSearchResto params:aParams delegate:aDelegate];
} - (void)findCityWithDelegate:(id<WFRequestDelegate>)aDelegate
{
[self createConnectionWithUrl:kSearchCity params:nil delegate:aDelegate];
} - (void)getCategoriesForBusinessesWithDelegate:(id<WFRequestDelegate>)aDelegate
{
[self createConnectionWithUrl:kCategoriesWithBusinesses params:nil delegate:aDelegate];
} //- (void)appendUTF8Body:(NSMutableData *)aBody dataString:(NSString *)aDataString
//{
// [aBody appendData:[aDataString dataUsingEncoding:NSUTF8StringEncoding]];
//} - (NSDictionary *)parseQueryString:(NSString *)query
{
NSMutableDictionary *paramDict = [[NSMutableDictionary alloc] initWithDictionary:0]; NSArray *paramArr = [query componentsSeparatedByString:@"&"];
for (NSString *param in paramArr)
{
NSArray * elements = [param componentsSeparatedByString:@"="];
if ([elements count] <= 1)
{
return nil;
} NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *value = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [paramDict setObject:value forKey:key];
} return paramDict;
} - (NSString *)serializeURL:(NSString *)aBaseURL params:(NSDictionary *)aParams
{
NSURL* parsedURL = [NSURL URLWithString:[aBaseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithDictionary:[self parseQueryString:[parsedURL query]]];
if (aParams) {
[paramsDic setValuesForKeysWithDictionary:aParams];
} NSMutableString *signString = [NSMutableString stringWithString:kDPAppKey];
NSMutableString *paramsString = [NSMutableString stringWithFormat:@"appkey=%@", kDPAppKey];
NSArray *sortedKeys = [[paramsDic allKeys] sortedArrayUsingSelector: @selector(compare:)];
for (NSString *key in sortedKeys) {
[signString appendFormat:@"%@%@", key, [paramsDic objectForKey:key]];
[paramsString appendFormat:@"&%@=%@", key, [paramsDic objectForKey:key]];
}
NSString *str = kDPAppSecret;
[signString appendString:str];
NSData *stringBytes = [signString dataUsingEncoding: NSUTF8StringEncoding];
NSString *digestString = [SHA1 getSHAString:stringBytes];
if (digestString)
{
[paramsString appendFormat:@"&sign=%@", [digestString uppercaseString]];
NSLog(@"...%@...", [NSString stringWithFormat:@"%@://%@%@?%@", [parsedURL scheme], [parsedURL host], [parsedURL path], [paramsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]);
return [NSString stringWithFormat:@"%@://%@%@?%@", [parsedURL scheme], [parsedURL host], [parsedURL path], [paramsString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
else
{
return nil;
}
} - (void) cancel
{
[_connection cancel];
} + (NSString *)getParamValueFromURL:(NSString *)aURl paramName:(NSString *)aParamName
{
return nil;
} #pragma mark - NSURLConnection Delegate Methods - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
_responseData = [[NSMutableData alloc] init];
} - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_responseData appendData:data];
} - (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error = nil;
id result= [NSJSONSerialization JSONObjectWithData:_responseData options:NSJSONReadingAllowFragments error:&error];
if (!result)
{
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:error,@"error", nil];
NSError *err = [NSError errorWithDomain:@"domain is error" code:-1 userInfo:userInfo];
if ([self.delegate respondsToSelector:@selector(request:didfailWithError:)])
{
[self.delegate request:self didfailWithError:err];
}
}
else
{
NSString *status = 0;
if ([result isKindOfClass:[NSDictionary class]])
{
status = [result objectForKey:@"status"];
} if ([status isEqualToString:@"OK"])
{
if ([self.delegate respondsToSelector:@selector(request:didfinishloadingWithResult:)])
{
[self.delegate request:self didfinishloadingWithResult:result == nil ?
_responseData : result];
}
}
else
{
if ([status isEqualToString:@"ERROR"])
{
//TODO:错误处理代码。
}
}
} // NSString *str = [[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
// NSLog(@"_responseData:%@", str); // [self clearData];
} - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR!%@", error.description);
} - (void)clearData
{
_responseData = nil;
[_connection cancel];
_connection = nil;
}
@end

代码下载。下节详细介绍数据解析和网络编程,反射(运行时)

初探iOS网络开发,数据解析。的更多相关文章

  1. ios网络_json数据解析

    网络上数据传输以json或者xml格式. json是字典 或者 数组 或者字典跟数组嵌套的形式.解析json就是把json反序列化(解析)---把json转换为oc对象.json序列化就是把oc对象转 ...

  2. Android网络之数据解析----SAX方式解析XML数据

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  3. iOS学习——JSON数据解析(十一)

    在之前的<iOS学习——xml数据解析(九)>介绍了xml数据解析,这一篇简单介绍一下Json数据解析.JSON 即 JavaScript Object Natation,它是一种轻量级的 ...

  4. Android网络之数据解析----使用Google Gson解析Json数据

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  5. 【原】iOS学习38网络之数据解析

    1. 解析的基本的概念 解析:从事先规定好的格式中提取数据 解析前提:提前约定好格式,数据提供方按照格式提供数据.数据获取方则按照格式获取数据 iOS开发常见的解析:XML解析.JOSN解析 2. X ...

  6. IOS网络开发概述

    概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力 ...

  7. iOS网络之数据请求GET和POST

    1. HTTP和HTTPS协议 1> URL URL全称是Uniform Resource Locator(统一资源定位符)通过1个URL,能找到互联网上唯一的1个资源 URL就是资源的地址.位 ...

  8. IOS网络开发(三)

    1 飞机航班查询软件 1.1 问题 NSURLConnection是IOS提供的用于处理Http协议的网络请求的类,可以实现同步请求也可以实现异步请求,本案例使用NSURLConnection类实现一 ...

  9. iOS学习之数据解析

    解析:按照约定好的格式提取数据的过程叫做解析; 后台开发人员按照约定好的格式存入数据,前端开发人员按照约定的格式读取数据; 主流的格式: XML / JSON 前端和后台都能识别的格式;  XML解析 ...

随机推荐

  1. Linux网络编程socket选项之SO_LINGER,SO_REUSEADDR

    from http://blog.csdn.net/feiyinzilgd/article/details/5894300 Linux网络编程中,socket的选项很多.其中几个比较重要的选项有:SO ...

  2. 面试题07_用两个栈实现队列——剑指offer系列

    题目描写叙述: 用两个栈实现一个队列. 队列的声明例如以下,请实现它的两个函数appendTail 和 deleteHead.分别完毕在队列尾部插入结点和在队列头部删除结点的功能. 解题思路: 栈的特 ...

  3. 快速将wax配置到项目中进行lua开发

    通过Finder浏览到你保存该项目的文件夹.创建三个新的文件夹:wax.scripts和Classes. 第一:首先,下载源代码的压缩包.Wax放在GitHub上(https://github.com ...

  4. Struts2 注解模式

    相信大家一定看到了两个class中定义了一样的action,不过看类的元数据,是不同的命名空间.这里比较重要(对我来说)的是 @Action(value = "/login", r ...

  5. C++ inline内联函数

    inline 函数避免函数调用的开销 // find longer of two strings const string &shorterString(const string &s ...

  6. WordPress主题开发:评论框

    方法一:调出内置评论框: 文章开启评论: 页面开启评论:(注意:如果使用的是插件,点快速编辑是没有“允许评论”可勾选的) 在对应的地方,插入 <?php comments_template(); ...

  7. python笔记33-python3连mysql增删改查

    前言 做自动化测试的时候,注册了一个新用户,产生了多余的数据,下次用同一账号就无法注册了,这种情况该怎么办呢? 自动化测试都有个数据准备和数据清理的操作,如果因为此用例产生了多余的数据,就需要数据清理 ...

  8. NSObject的hash方法

    NSObject的hash方法 说明 本示例仅仅演示一个对象什么时候执行hash方法. 细节 1. 必要的Model类,重载了hash方法用以反映Hash方法是否被调用了 2. 测试 // // Vi ...

  9. c# action<> func<> 这2个委托怎么用和理解

    其实很好理解的呢!~首先你需要明白,他们是委托的简写形式. 一.[action<>]指定那些只有输入参数,没有返回值的委托 1.1定义一个委托: 比如,我们原来写委托: public de ...

  10. Apache的三种工作模式

    Web服务器Apache目前一共有三种稳定的MPM(Multi-Processing Module,多进程处理模块)模式. 它们分别是prefork,worker和event,它们同时也代表这Apac ...