通过大众点评平台开发来简单了解一下,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. Docker 传奇之 dotCloud

    2010年,几个大胡子年轻人在旧金山成立了一家做 PaaS 平台的公司,起名为「dotCloud」,这个名字让我想起了微软的「DotNet」. dotCloud 主要是基于 PaaS 平台为开发者或开 ...

  2. 淘宝应对"双11"的技术架构分析

    原文地址:http://kb.cnblogs.com/page/193670/ 双“11”最热门的话题是TB ,最近正好和阿里的一个朋友聊淘宝的技术架构,发现很多有意思的地方,分享一下他们的解析资料: ...

  3. C#编程(五十八)----------并行集合

    并行集合 对于并行任务,与其相关紧密的就是对一些共享资源,数据结构的并行访问.经常要做的就是对一些队列进行加锁-解锁,然后执行类似插入,删除等等互斥操作. .NET4提供了一些封装好的支持并行操作数据 ...

  4. shapefile与字符集编码设置

    在 ArcGIS Desktop (ArcMap, ArcCatalog, and ArcToolbox) 中,有编码页转换功能(CODE PAGE CONVERSION),可以读写多种字符编码的 s ...

  5. go 用的不多的命令

    8.go doc 文档注释相关,可以搭建本地GO文档服务器,包含自己的项目注释,更多细节请参考:https://github.com/hyper-carrot/go_command_tutorial/ ...

  6. Mybatis ResultMap Collection 复合主键

    <resultMap type="XX" id="XXMap">          <id property="id" c ...

  7. 罪恶黑名单第一季/全集The Blacklist迅雷下载

    罪恶黑名单 第一季 The Blacklist Season 1 (2013)本季看点:几十年来,绰号「红魔」(Red)的前军事情报官员Raymond Reddington(James Spader) ...

  8. spring源代码分析

    预初始化beanDefaultListableBeanFactory preInstantiateSingletons

  9. 以绑定的方式来启动service

    先说下原理,之前我们的启动service就是用startService来启动的,这是显式启动.启动后我们无法得到service中的数据,也无法知道它执行的状态,如果我们要启动它的activity和它建 ...

  10. SimpleAdapter和AutoCompleteTextView配合使用

     修改后成为这样→    package com.kale.autocompletetextview; import java.util.ArrayList; import java.util.Has ...