http://blog.csdn.net/zengraoli/article/details/12918369 在blog文 iOS使用ASIHttpRequestJson与服务器段脚本进行登陆验证 中,没有仔细的说清楚,到底是如何交互的,很是抱歉;毕竟我用php也仅限于这几天。。 先来看,我刚才写的一个php端: [php] view p
http://blog.csdn.net/zengraoli/article/details/12918369
在blog文
iOS使用ASIHttpRequest+Json与服务器段脚本进行登陆验证
中,没有仔细的说清楚,到底是如何交互的,很是抱歉;毕竟我用php也仅限于这几天。。
先来看,我刚才写的一个php端:
[php] view plaincopyprint?
- $arr;
- function traverse($path = '.')
- {
- $current_dir = opendir($path); //opendir()返回一个目录句柄,失败返回false
- $directory_arr;
- $file_arr;
- $directory_index = 1;
- $file_index = 1;
- Global $arr;
- $arr_index = 0;
- while(($file = readdir($current_dir)) !== false)
- { //readdir()返回打开目录句柄中的一个条目
- $sub_dir = $path . DIRECTORY_SEPARATOR . $file; //构建子目录路径
- if($file == '.' || $file == '..')
- {
- continue;
- }
- else if(is_dir($sub_dir))
- { //如果是目录,进行递归
-
// echo 'Directory ' . $file . ':
'; - $string = "Directory";
- $string .= $directory_index;
- $directory_arr[$string] = $file;
- $directory_index++;
- traverse($sub_dir);
- // print_r($directory_arr);
- }
- else
- { //如果是文件,直接输出
-
// echo 'File in Directory ' . $path . ': ' . $file . '
'; -
$file_arr[$file_index] = $path . '\\' . $file . '
'; - $file_index++;
- }
- };
- $arr["dir_count"] = count($directory_arr);
- // print_r($file_arr);
- // print_r(count($file_arr));
-
// echo '
'; - // echo "==============================";
-
// echo '
'; - // 有一个是title需要先减出来,还有一半是.txt
- $arr[$path] = (count($file_arr) - 1) / 2;
- }
- traverse('Images');
- // print_r($arr);
- // print_r(json_encode($arr));
- $resultJson = json_encode($arr);
- echo $resultJson;
- ?>
在服务器端直接运行这个php脚本之后得到的页面如下:
这是一个获取当前webroot目录下,Images文件夹里面的目录个数,和这些目录个数下面.jpg文件个数的一个demo
这是其中一个day1的内容:
在对应的iOS端,这样写:
[cpp] view plaincopyprint?
- //
- // ViewController.m
- // Demo
- //
- // Created by zengraoli on 13-10-20.
- // Copyright (c) 2013年 zeng. All rights reserved.
- //
- #import "ViewController.h"
- #import "UIView+Additon.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- [self getResourcesCount];
- }
- -(void)getResourcesCount
- {
- NSString *baseurl=@"get_resources_count.php";
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",host_url,baseurl]];
- [self setRequest:[ASIHTTPRequest requestWithURL:url]];
- [_request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
- [_request startSynchronous];
- //显示网络请求信息在status bar上
- [ASIHTTPRequest setShouldUpdateNetworkActivityIndicator:YES];
- if (_request)
- {
- if ([_request error])
- {
- NSLog(@"error");
- }
- else if ([_request responseString])
- {
- NSString *result = [_request responseString];
- // NSLog(@"%@",result);
- NSDictionary *mydict = [result JSONValue];
- describeDictionary(mydict);
- }
- }
- else
- {
- NSLog(@"request is nil.");
- }
- }
- void describeDictionary(NSDictionary *dict)
- {
- NSArray *keys;
- int i, count;
- id key, value;
- keys = [dict allKeys];
- count = [keys count];
- for (i = 0; i
- {
- key = [keys objectAtIndex: i];
- value = [dict objectForKey: key];
- NSLog (@"Key: %@ for value: %@", key, value);
- }
- }
- @end
这是调用这段代码后,解析Json数据得到的结果:

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기
