ios开发——JSON解析
来源:互联网 发布:网络新歌2017伤感歌曲 编辑:程序博客网 时间:2024/05/30 05:06
ios开发JSON解析
解析经纬度
- (IBAction)buttonInsideOk:(id)sender {
//得到请求地址,进行请求,返回JSON
NSString *urlInput = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",self.textJSONInput.text];
NSURL *urlJSON = [NSURL URLWithString:urlInput];
NSData *dataJSON = [NSData dataWithContentsOfURL:urlJSON];
//解析JSON
NSError *errorJSON = [[NSError alloc] init];
id temp = [NSJSONSerialization JSONObjectWithData:dataJSON options:NSJSONReadingMutableContainers error:&errorJSON];
Class classType = [temp class];
if([classType isSubclassOfClass:[NSDictionary class]]){
NSDictionary *dictJSON = (NSDictionary *)temp;
NSArray *arrResult = [dictJSON objectForKey:@"results"];
for(id single in arrResult){
NSDictionary *tempArrResult = single;
//取地址
NSString *dictAddress = [tempArrResult objectForKey:@"formatted_address"];
self.labAddress.text = dictAddress;
//自定义地址显示格式
NSArray *arrAddress = [tempArrResult objectForKey:@"address_components"];
NSString *myAddress ;
int dm_i = 0;
for(id tempAd in arrAddress){
NSDictionary *tempAddress = (NSDictionary *)tempAd;
if(dm_i == 0){
NSString *myAppend = [NSString stringWithFormat:@"%@", [tempAddress objectForKey:@"long_name"]];
myAddress = myAppend;
dm_i += 1;
}else{
NSString *myAppend = [NSString stringWithFormat:@"%@-%@", [tempAddress objectForKey:@"long_name"],myAddress];
myAddress = myAppend;
}
}
self.textMyAddress.text = myAddress;
//几何学,
NSDictionary *tempDictArr = [tempArrResult objectForKey: @"geometry"];
//地点,位置
NSDictionary *dictGeometry = [tempDictArr objectForKey:@"location"];
//取经度
self.labOne.text = [NSString stringWithFormat:@"%@",[dictGeometry objectForKey:@"lng"]];
//取纬度
self.labTwo.text = [NSString stringWithFormat:@"%@",[dictGeometry objectForKey:@"lat"]];
}
NSLog(@"%@",dictJSON);
}else if([classType isSubclassOfClass:[NSArray class]]){
NSArray *arrJSON = (NSArray *)temp;
}
//提取有效数据,显示到UI上
}
- ios开发——JSON解析
- iOS网络编程开发—JSON解析与XML解析
- iOS开发 - JSON解析
- iOS开发,json解析
- iOS网络开发——解析与封装JSON数据
- IOS开发指南学习——Json解析
- iOS开发——XML/JSON数据解析
- iOS开发——XML/JSON数据解析
- iOS开发网络篇—JSON数据的解析
- iOS开发网络篇—JSON数据的解析
- iOS开发网络篇—JSON数据的解析
- iOS——JSON解析
- iOS开发网络 -- JSON解析
- iOS开发-Day33-JSON解析
- iOS开发 JSON解析 NSJSONSerialization
- iOS开发之json解析
- ios开发 解析Json数组
- 《iOS开发笔记—JSON》
- Cocos2d-x PluginX (一)使用手册
- ios 打开图片库和相机选择图片界面修改为简体中文
- c# for foreach执行效率比较
- 罗大柚OpenGL ES教程系列LessonTwo(Part 3):采用VAO和index,绘制一个Cube
- JSONException:java.lang.String cannot be converted to JSONObject
- ios开发——JSON解析
- 解决myeclipse 光标乱跳问题
- Amazon AWS亚马逊云服务新服务简介(DynamoDB, Redshift,Kinesis)
- android debug,知识点总结
- ORA-12560: TNS: 协议适配器错误
- 三星Note 3大卖 苹果错失Phablet商机
- 小布老师ORACLE 性能调优
- 开博记事
- Hive开发中使用变量的两种方法