- (NSString*)getWANIP{
NSError*error;
NSURL *ipURL = [NSURL URLWithString:@"http://pv.sohu.com/cityjson?ie=utf-8"];
NSMutableString *ip = [NSMutableString stringWithContentsOfURL:ipURL encoding:NSUTF8StringEncoding error:&error];
// var returnCitySN = {"cip": "175.10.145.8", "cid": "430000", "cname": "湖南省"};
//判断返回字符串是否为所需数据
if ([ip hasPrefix:@"var returnCitySN = "]) {
//删除字符串多余字符串
NSRangerange =NSMakeRange(0,19);
[ipdeleteCharactersInRange:range];
NSString* nowIp =[ipsubstringToIndex:ip.length-1];
//将字符串转换成二进制进行Json解析
NSData* data = [nowIpdataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* dict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];
NSLog(@"%@",dict);
returndict[@"cip"] ? dict[@"cip"] :@"";
}
return@"";
}