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 Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 Linux新版
SublimeText3 Linux最新版

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。