1:先在项目里引入json:
#import "JSON.h"
2:然后将服务端返回的数据进行反解码:
id jsonValue = [response JSONValue];
3:最后得到的就是一个数组
4:具体代码:
- - (IBAction)sendrequest:(id)sender {
- // ASIHTTPRequest function start
- NSURL *newurl = [NSURL URLWithString:address.text];
- ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:newurl];
- [request startSynchronous];
- NSError *error = [request error];
- int i;
- if(!error)
- {
- NSString *response = [request responseString];
- id jsonValue = [response JSONValue];
- for(i=0;i<[jsonValue count];i++)
- {
- NSLog(@"content is:%@",[jsonValue objectAtIndex:i]);
- }
- [response release];
- }
- // ASIHTTPRequest the end.
- }
转载于:https://blog.51cto.com/ruisi/749192