本人不才,自己封装了一个方法,使用本方法 只需传入一个json拼接字符串,一个url字符串,将会获得一个NSDictionary字典数据
#import <Foundation/Foundation.h>
#import "JSON.h"
@interface HttpServer : NSObject
{
NSString *urlString;
NSString *jsonString;
}
-(NSDictionary *)JSONString:(NSString *)jsonString URLString:(NSString *)urlString;
@end
#import "HttpServer.h"
@implementation HttpServer
-(NSDictionary *)JSONString:(NSString *)jsonString URLString:(NSString *)urlString{
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:30.0f];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSString *result = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [result JSONValue];
return dictionary;
}
@end
Jquery实现仿搜索引擎文本框自动补全插件功能很实用,使用也很简单,引入了插件之后写几行代码就可以实现,可以灵活设置 //width:下拉框的宽度,默认使用输入框宽度、用来ajax后台获取数据,返回的数据格式为data参数一样、数据格式{data:[{title:null,result:{}},{title:null,result:{}}]}url和data参数只有一个生效,data优先、选中行后按回车或单击时回调的函数
下载地址:http://download.csdn.net/detail/luck332/4961685
NSDictionary *userDefaults;
@property (nonatomic, retain) NSDictionary *userDefaults;
在AppDelegate.m里 @synthesize userDefaults;
//本地存储密码
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
[userDefault setObject:user forKey:@"user"];
[userDefault setObject:pwd forKey:@"pwd"];
AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];
myDelegate.userDefaults = userDefault;
//取用户名密码
AppDelegate *myDelegate = [[UIApplication sharedApplication]delegate];
NSString *user = [myDelegate.userDefaults valueForKey:@"user"];
NSString *pwd = [myDelegate.userDefaults valueForKey:@"pwd"];
好了,大功告成。