好久没写文章了,我也心痒痒的,嘿嘿。现在写一篇文章。
好了 最近调查的任务颇多,也没来得及写下来。
好了 开始
1. 我今天要说的,大家可能已经知道。怎么用JQuery访问后台,交互的方式就是JSon,对于拿哥来说,这个比较简单,嘿嘿
,在这里也瞥我啊,自己会就会把
2.给出Server端的code
List<Person> persons = personService.getPersonList(); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter pw= response.getWriter(); JSONArray json_ps = JSONArray.fromObject(persons); pw.write(json_ps.toString());
这个是抄袭过来的。我本身的目的不是后台
3.JQuery 代码
$.post( 'tableoperation.htm', {}, function (data) { console.log(data.column); } );
好了。
var person = '{"id":5,"name":"aa","age":25,"high":155.00}';
String personJ = request.getParameter("personStr");
JSONObject jsonObject = JSONObject.fromObject(personJ);
Person person = (Person)JSONObject.toBean(jsonObject,Person.class);
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
在早些时候,当iOS 6还没出来的时候,我们访问通讯录只要如下简单的代码:
ABAddressBookRef addressBook = ABAddressBookCreate();
不过在iOS 6上,这个API返回空值。这时候需要用到如下代码:
// Call ABAddressBookCreateWithOptions to create an instance of AddressBook. The // ABAddressBookRef will initially not have access to contact data. The app must // then call ABAddressBookRequestAccessWithCompletion to request this access. // The options argument is reserved for future use. Currently it will always be NULL. // If access to contact data is already restricted or denied, this will fail returning // a NULL ABAddressBookRef with error kABOperationNotPermittedByUserError. AB_EXTERN ABAddressBookRef ABAddressBookCreateWithOptions(CFDictionaryRef options, CFErrorRef* error) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0);
由于之前的iOS 版本在隐私方面被人诟病,以至于出现App在没有提醒用户的情况访问通讯录而被拒绝的案例。现在每个App要访问通讯录都应该得到用户的授权:
因此,如上注释所描述的,我们应该调用如下API来获取授权:
// Users are able to grant or deny access to contact data on a per-app basis. To request // access to contact data, call ABAddressBookRequestAccessWithCompletion. This will not // block the app while the user is being asked to grant or deny access. Until access has // been granted, a non-NULL ABAddressBookRef will not contain any contacts and any attempt to // modify contacts will fail with CFErrorRef returning kABOperationNotPermittedByUserError. // The user will only be prompted the first time access is requested; any subsequent calls // to ABAddressBookCreateWithOptions will use the existing permissions. The completion // handler is called on an arbitrary queue. If the ABAddressBookRef is used throughout the app, // then all usage should be dispatched to the same queue to use ABAddressBookRef in a // thread-safe manner. typedef void(^ABAddressBookRequestAccessCompletionHandler)(bool granted, CFErrorRef error); AB_EXTERN void ABAddressBookRequestAccessWithCompletion(ABAddressBookRef addressBook, ABAddressBookRequestAccessCompletionHandler completion) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0);
ABAddressBookRef addressBook = NULL; __block BOOL accessGranted = NO; if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6 dispatch_semaphore_t sema = dispatch_semaphore_create(0); ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { accessGranted = granted; dispatch_semaphore_signal(sema); }); dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); dispatch_release(sema); } else { // we're on iOS 5 or older accessGranted = YES; } if (accessGranted) { // Do whatever you want here. }
不过这只会在第一次时才显示对话框,如果用户已经拒绝了,我们可以判断下授权状态:
// To check the app's access to contact data. Based upon the access, the app could // display or hide its UI elements that would access any AddressBook API. // // kABAuthorizationStatusNotDetermined // The user has not yet made a choice regarding whether this app can access the data class. // // kABAuthorizationStatusRestricted // This application is not authorized to access the data class. The user cannot change // this application’s status, possibly due to active restrictions such as parental controls // being in place. // // kABAuthorizationStatusDenied // The user explicitly denied access to the data class for this application. // // kABAuthorizationStatusAuthorized // This application is authorized to access the data class. // typedef CF_ENUM(CFIndex, ABAuthorizationStatus) { kABAuthorizationStatusNotDetermined = 0, kABAuthorizationStatusRestricted, kABAuthorizationStatusDenied, kABAuthorizationStatusAuthorized }; AB_EXTERN ABAuthorizationStatus ABAddressBookGetAuthorizationStatus(void) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0);
通过判断授权状态,我们可以再次提醒用户进行授权。
比较糟糕的是,在中文版上,访问通讯录会出现汉化错误,XXX 想访问您的日历:
我突然发现微信还给了用户更为详细的信息,表示现在是要访问通讯录,而非日历。于是,我在上面提到的代码中翻了几遍,都没找到设置alertView详细信息的地方,最后在SO上得到解答 —— 通过在plist设置NSContactsUsageDescription关键字。详细文档见此。
注:本文的主要目的是为了记录自己的学习过程,也方便与大家做交流。转载请注明来自:
http://blog.csdn.net/ab198604
栈是一种按照先进后出的数据存储结构(LIFO),它检索元素的顺序与存储元素的顺序是相反的。所谓的先进后出是指数据元素的存储与删除操作,这意味着最后一个存储的元素将会第一个被删除。举个例子,现在要把"5,4,3,2,1"存入到“栈”中,从栈的底部到顶部分别是5,4,3,2,1,当删除时,顺序为“1,2,3,4,5”。
不说理论了,来点干货。如何实现“栈”这种数据结构呢?其实,实现栈的方法有很多,可以用顺序的线性存储结构和链式的非线性存储结构。顺序存储结构如数组的方式。链式存储结构,顾名思义,是采用链表的存储方式。采用链表的方式来实现栈不仅操作简单,而且可以使栈具有多态的特性。这是因为除了栈本身的一些操作外,它毕竟本身就是一种链表,它具有与链表的相同属性。因此还可以使用链表的一些操作。所以本文采用链表的方式来实现栈。
二、栈的结构及接口定义由于栈是链表的另一种表现形式,所以对栈的结构定义可以在链表的基础上进行一次封装。如下所示:
/* * filename: stack.h * author:zhm * date:2012-01-05 */ #ifndef STACK_H #define STACK_H #include <stdlib.h> #include "list.h" typedef List Stack;//对List类型重新定义对链表的结构定义及接口,在《数据结构学习之单向链表结构》已经说明,这里不再讲述,有需要的朋友可以登录这个地址访问相关的内容:
http://blog.csdn.net/ab198604/article/details/8253405
由上面的typedef List Stack语句就已经实现了栈结构的定义了。下面为栈的相关操作:
/* public interface */ #define stack_init list_init #define stack_destroy list_destroy int stack_push(Stack *stack, const void *data); int stack_pop(Stack *stack, void **data); #define stack_peek(stack) ((stack)->head == NULL ? NULL : (stack)->head->data) #define stack_size list_size主要有栈的初始化,栈的销毁,压栈操作,入栈操作等。栈的初始化、销毁及栈元素大小获取等都是在原链表接口的基础上用#define语句进一步封装而成。 三、栈的接口实现细节
真正要实现的就是压栈和入栈操作了,通过调用链表的接口就能实现,看下面代码:
/* * filename: stack.c * author: zhm * date: 2012-01-05 */ #include <stdlib.h> #include "list.h" #include "stack.h" /* stack_push */ int stack_push(Stack *stack, const void *data) { /* push the data onto the stack */ return list_ins_next(stack, NULL, data); } /* stack_pop */ int stack_pop(Stack *stack, void **data) { /* pop the data off the stack */ return list_rem_next(stack, NULL, data); }四、栈的应用举例
看下面代码:
/* * filename: main.c * author:zhm * date: 2013-01-05 */ #include <string.h> #include <stdlib.h> #include <stdio.h> #include "list.h" #include "stack.h" /* destroy */ void destroy(void *data) { printf("in destroy\n"); free(data); return; } /* main */ int main(int argc, char **argv) { Stack stack; int *int_ptr = NULL; int ret = 0; int i; stack_init(&stack, destroy); for(i = 0; i < 5; i++ ) { int_ptr = (int *)malloc(sizeof(int)); if( int_ptr == NULL ) return -1; *int_ptr = i; printf("push the data: %d\n",i); ret = stack_push(&stack, (void *)int_ptr); if( ret != 0 ) return -1; } printf("size of the stack is : %d\n", stack_size(&stack)); //pop the data from top to the bottom for(i = stack_size(&stack); i > 0; i-- ) { int_ptr = NULL; stack_pop(&stack, (void **)&int_ptr); printf("i = %d, pop the data = %d\n",i,*int_ptr); free(int_ptr); } printf("after pop size of the stack is :%d\n", stack_size(&stack)); return 0; }上述main()函数所实现的功能主要是将数据:0,1,2,3,4分别压入栈中,然后将其一一从栈顶弹出。程序经过编译运行后,结果如下所示: