`
iaiai
  • 浏览: 2144641 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[IOS] 用json-framework解析json数据

 
阅读更多
下载json-framework
https://github.com/stig/json-framework/

//http访问接口返回json
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://iaiai.iteye.com"]];
[request setHTTPMethod:method];
        
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSMutableString *result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

//把json转成对象
//NSDictionary* json = [result JSONValue];
NSMutableArray* json = [result JSONValue];
NSArray* list = [NSArray alloc];
for (NSDictionary *dictionary in json){//对NSMutableArray进行遍历
  NSLog(@"%@,%@",[dictionary objectForKey:@"appType"],[dictionary objectForKey:@"copyright"]);
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics