Iphone 按大陆对国家进行排序
有没有办法得到一个特定国家的大陆 我正在使用Flurry的API,它返回一个由国家分隔的JSON,我需要contintent中的数据,所以我希望每个contintent都有一个数组,其中包含他的国家,例如:Iphone 按大陆对国家进行排序,iphone,ios,flurry,nslocale,Iphone,Ios,Flurry,Nslocale,有没有办法得到一个特定国家的大陆 我正在使用Flurry的API,它返回一个由国家分隔的JSON,我需要contintent中的数据,所以我希望每个contintent都有一个数组,其中包含他的国家,例如: NSArray * europe = [[NSArray alloc] initWithObjects:@"ES", @"IT", @"FR", ... , nil]; 提前谢谢 声明反向查找字典: NSDictionary *continentForCountries = @{
NSArray * europe = [[NSArray alloc] initWithObjects:@"ES", @"IT", @"FR", ... , nil];
提前谢谢 声明反向查找字典:
NSDictionary *continentForCountries = @{
@"FR": @"Europe",
@"IT": @"Europe",
@"US": @"North America",
@"CA": @"North America",
...
}
然后,您可以使用EnumerateObjectsSusingBlock
将国家分组为大陆,在其中,您可以将国家累积到数组字典中,数组的键是大陆名称:
NSArray *countries = @[...];
NSArray *continentForCountries = @[...];
NSMutableDictionary *countriesByContinents = [NSMutableDictionary new];
[countries enumerateObjectsUsingBlock:^(NSString *country, NSUInteger idx, BOOL *stop) {
NSString *continent = continentForCountries[country];
if (countriesByContinents[continent] == nil)
countriesByContinents[continent] = [NSMutableArray new];
[countriesByContinents[continent] addObject:country];
}];
您可以使用以下选项:
private static HashMap<String,String> countryMap=new HashMap<String,String>();
private final static String EUROPE="E";
private final static String NORTH_AMERICA="N";
private final static String SOUTH_AMERICA="S";
private final static String AFRICA="AF";
private final static String ASIA="AS";
private final static String OCEANIA="O";
private final static String ANTARTIDA="ANT";
static
{
countryMap.put("AF", "AS");
countryMap.put("AL", "E");
countryMap.put("DE", "E");
countryMap.put("DZ", "E");
countryMap.put("AD", "E");
countryMap.put("AQ", "ANT");
countryMap.put("AG", "S");
countryMap.put("SA", "AS");
countryMap.put("AR", "S");
countryMap.put("AM", "AS");
countryMap.put("AW", "S");
countryMap.put("AU", "O");
countryMap.put("AZ", "AS");
countryMap.put("AT", "E");
countryMap.put("BS", "S");
countryMap.put("BH", "AS");
countryMap.put("BD", "AS");
countryMap.put("BB", "S");
countryMap.put("BZ", "S");
countryMap.put("BJ", "AF");
countryMap.put("BM", "S");
countryMap.put("BE", "E");
countryMap.put("BT", "AS");
countryMap.put("BE", "E");
countryMap.put("BO", "S");
countryMap.put("BW", "AF");
countryMap.put("BA", "E");
countryMap.put("BR", "S");
countryMap.put("BN", "AS");
countryMap.put("BG", "E");
countryMap.put("BF", "AF");
countryMap.put("BI", "AF");
countryMap.put("KH", "AS");
countryMap.put("CM", "AF");
countryMap.put("CA", "N");
countryMap.put("CV", "AF");
countryMap.put("BQ", "S");
countryMap.put("AF", "AS");
countryMap.put("CO", "S");
countryMap.put("KM", "AF");
countryMap.put("CG", "AF");
countryMap.put("CD", "AF");
countryMap.put("KP", "AS");
countryMap.put("KR", "AS");
countryMap.put("CR", "S");
countryMap.put("CI", "AF");
countryMap.put("HR", "E");
countryMap.put("CU", "S");
countryMap.put("CW", "S");
countryMap.put("DK", "E");
countryMap.put("DJ", "AF");
countryMap.put("DM", "S");
countryMap.put("EG", "AF");
countryMap.put("SV", "S");
countryMap.put("EC", "S");
countryMap.put("ER", "AF");
countryMap.put("SK", "E");
countryMap.put("SI", "E");
countryMap.put("ES", "E");
countryMap.put("US", "N");
countryMap.put("EE", "E");
countryMap.put("ET", "AF");
countryMap.put("FJ", "O");
countryMap.put("PH", "AS");
countryMap.put("FI", "E");
countryMap.put("FR", "E");
countryMap.put("GA", "AF");
countryMap.put("GM", "AF");
countryMap.put("GE", "E");
countryMap.put("GH", "AF");
countryMap.put("GI", "E");
countryMap.put("GD", "S");
countryMap.put("GL", "N");
countryMap.put("GP", "S");
countryMap.put("GF", "S");
countryMap.put("GU", "AF");
countryMap.put("GT", "S");
countryMap.put("GG", "E");
countryMap.put("GN", "AF");
countryMap.put("GW", "AF");
countryMap.put("GQ", "AF");
countryMap.put("GY", "S");
countryMap.put("HT", "S");
countryMap.put("HN", "S");
countryMap.put("HN", "E");
countryMap.put("IE", "AS");
countryMap.put("BV", "ANT");
countryMap.put("CX", "O");
countryMap.put("HM", "ANT");
countryMap.put("AF", "O");
countryMap.put("IM", "E");
countryMap.put("RE", "AF");
countryMap.put("KY", "S");
countryMap.put("CC", "O");
countryMap.put("CK", "O");
countryMap.put("FO", "E");
countryMap.put("GS", "ANT");
countryMap.put("FK", "S");
countryMap.put("MP", "O");
countryMap.put("MH", "O");
countryMap.put("UM", "O");
countryMap.put("PN", "S");
countryMap.put("SB", "O");
countryMap.put("TC", "S");
countryMap.put("VG", "S");
countryMap.put("VI", "S");
countryMap.put("ID", "AS");
countryMap.put("IR", "AS");
countryMap.put("IQ", "AS");
countryMap.put("IE", "E");
countryMap.put("IS", "E");
countryMap.put("IL", "AS");
countryMap.put("IT", "E");
countryMap.put("IN", "AS");
countryMap.put("JM", "S");
countryMap.put("JP", "AS");
countryMap.put("JE", "E");
countryMap.put("JO", "AS");
countryMap.put("KZ", "AS");
countryMap.put("KE", "AF");
countryMap.put("KG", "AS");
countryMap.put("KI", "O");
countryMap.put("KW", "AS");
countryMap.put("LA", "AS");
countryMap.put("LV", "E");
countryMap.put("LR", "AF");
countryMap.put("LI", "E");
countryMap.put("LT", "E");
countryMap.put("LB", "AS");
countryMap.put("LY", "AF");
countryMap.put("LU", "E");
countryMap.put("MK", "E");
countryMap.put("MG", "AF");
countryMap.put("MW", "AF");
countryMap.put("MV", "AS");
countryMap.put("ML", "AF");
countryMap.put("MT", "E");
countryMap.put("MA", "AF");
countryMap.put("MQ", "S");
countryMap.put("MU", "AF");
countryMap.put("MR", "AF");
countryMap.put("YT", "AF");
countryMap.put("MX", "N");
countryMap.put("FM", "O");
countryMap.put("MZ", "AF");
countryMap.put("MD", "E");
countryMap.put("MN", "AS");
countryMap.put("ME", "E");
countryMap.put("MS", "S");
countryMap.put("MC", "E");
countryMap.put("MM", "AS");
countryMap.put("NA", "AF");
countryMap.put("NR", "O");
countryMap.put("NP", "AS");
countryMap.put("NI", "S");
countryMap.put("NG", "AF");
countryMap.put("NU", "O");
countryMap.put("NE", "AF");
countryMap.put("NO","E");
countryMap.put("NC", "O");
countryMap.put("NZ", "O");
countryMap.put("OM", "AS");
countryMap.put("NL", "E");
countryMap.put("PK", "AS");
countryMap.put("PW", "O");
countryMap.put("PS", "AS");
countryMap.put("PA", "S");
countryMap.put("PG", "O");
countryMap.put("PY", "S");
countryMap.put("PE", "S");
countryMap.put("PF", "O");
countryMap.put("PL", "E");
countryMap.put("PT", "E");
countryMap.put("PR", "S");
countryMap.put("QA", "AS");
countryMap.put("HK", "AS");
countryMap.put("MO", "AS");
countryMap.put("GB", "E");
countryMap.put("CF", "E");
countryMap.put("DO", "S");
countryMap.put("CZ", "E");
countryMap.put("ZA", "AF");
countryMap.put("RO", "E");
countryMap.put("RU", "E");
countryMap.put("RW", "AF");
countryMap.put("UM", "S");
countryMap.put("KN", "S");
countryMap.put("SH", "AF");
countryMap.put("LC", "S");
countryMap.put("MF", "S");
countryMap.put("VC", "S");
countryMap.put("PM", "N");
countryMap.put("WS", "O");
countryMap.put("AS", "O");
countryMap.put("SM", "E");
countryMap.put("EH", "AF");
countryMap.put("ST", "AF");
countryMap.put("SN", "AF");
countryMap.put("SC", "AF");
countryMap.put("RS", "E");
countryMap.put("SL", "AF");
countryMap.put("SG", "AS");
countryMap.put("SR", "S");
countryMap.put("SJ", "E");
countryMap.put("SZ", "AF");
countryMap.put("TJ", "AS");
countryMap.put("TH", "AS");
countryMap.put("TW", "AS");
countryMap.put("TZ", "AF");
countryMap.put("IO", "O");
countryMap.put("TF", "O");
countryMap.put("TL", "AS");
countryMap.put("TG", "AF");
countryMap.put("TK", "O");
countryMap.put("TO", "O");
countryMap.put("TT", "S");
countryMap.put("TN", "AF");
countryMap.put("TM", "AS");
countryMap.put("TR", "AS");
countryMap.put("TV", "O");
countryMap.put("TD", "AF");
countryMap.put("UA", "E");
countryMap.put("UG", "AF");
countryMap.put("AE", "AS");
countryMap.put("UY", "S");
countryMap.put("UZ", "AS");
countryMap.put("VZ", "O");
countryMap.put("VA", "E");
countryMap.put("VE", "S");
countryMap.put("VN", "AS");
countryMap.put("WF", "O");
countryMap.put("CL", "S");
countryMap.put("CN", "AS");
countryMap.put("CY", "E");
countryMap.put("ZM", "AF");
countryMap.put("ZW", "AF");
}
private static HashMap countryMap=new HashMap();
私有最终静态字符串EUROPE=“E”;
专用最终静态字符串NORTH_AMERICA=“N”;
私有最终静态字符串SOUTH_AMERICA=“S”;
私有最终静态字符串AFRICA=“AF”;
私有最终静态字符串ASIA=“AS”;
专用最终静态字符串OCEANIA=“O”;
私有最终静态字符串ANTARTIDA=“ANT”;
静止的
{
countryMap.put(“AF”、“AS”);
countryMap.put(“AL”、“E”);
国家地图.put(“DE”、“E”);
国家地图。put(“DZ”、“E”);
国家地图。put(“AD”、“E”);
countryMap.put(“AQ”、“ANT”);
countryMap.put(“AG”、“S”);
countryMap.put(“SA”、“AS”);
countryMap.put(“AR”、“S”);
countryMap.put(“AM”、“AS”);
国家地图。put(“AW”、“S”);
国家地图.put(“AU”、“O”);
countryMap.put(“AZ”、“AS”);
国家地图。放置(“AT”,“E”);
countryMap.put(“BS”、“S”);
countryMap.put(“BH”、“AS”);
countryMap.put(“BD”、“AS”);
countryMap.put(“BB”、“S”);
countryMap.put(“BZ”、“S”);
countryMap.put(“BJ”、“AF”);
countryMap.put(“BM”、“S”);
countryMap.put(“BE”、“E”);
countryMap.put(“BT”、“AS”);
countryMap.put(“BE”、“E”);
countryMap.put(“BO”、“S”);
countryMap.put(“BW”、“AF”);
国家地图。put(“BA”、“E”);
countryMap.put(“BR”、“S”);
countryMap.put(“BN”、“AS”);
countryMap.put(“BG”、“E”);
国家地图。put(“BF”、“AF”);
countryMap.put(“BI”、“AF”);
countryMap.put(“KH”、“AS”);
国家地图。put(“CM”、“AF”);
countryMap.put(“CA”、“N”);
countryMap.put(“CV”、“AF”);
countryMap.put(“BQ”、“S”);
countryMap.put(“AF”、“AS”);
countryMap.put(“CO”、“S”);
国家地图。put(“KM”、“AF”);
countryMap.put(“CG”、“AF”);
countryMap.put(“CD”、“AF”);
countryMap.put(“KP”、“AS”);
countryMap.put(“KR”、“AS”);
countryMap.put(“CR”、“S”);
countryMap.put(“CI”、“AF”);
countryMap.put(“HR”、“E”);
countryMap.put(“CU”、“S”);
countryMap.put(“CW”、“S”);
国家地图。put(“DK”、“E”);
countryMap.put(“DJ”、“AF”);
countryMap.put(“DM”、“S”);
国家地图.put(“例如”,“AF”);
countryMap.put(“SV”、“S”);
countryMap.put(“EC”、“S”);
国家地图.put(“ER”,“AF”);
国家地图。put(“SK”、“E”);
国家地图。put(“SI”、“E”);
countryMap.put(“ES”、“E”);
countryMap.put(“美国”、“N”);
国家地图.put(“EE”、“E”);
国家地图。put(“ET”、“AF”);
国家地图。put(“FJ”、“O”);
countryMap.put(“PH”、“AS”);
countryMap.put(“FI”、“E”);
countryMap.put(“FR”、“E”);
countryMap.put(“GA”、“AF”);
countryMap.put(“GM”、“AF”);
countryMap.put(“GE”、“E”);
国家地图。放置(“GH”、“AF”);
国家地图。put(“GI”、“E”);
countryMap.put(“GD”、“S”);
countryMap.put(“GL”、“N”);
countryMap.put(“GP”、“S”);
countryMap.put(“GF”、“S”);
国家地图。put(“GU”、“AF”);
countryMap.put(“GT”、“S”);
countryMap.put(“GG”、“E”);
countryMap.put(“GN”、“AF”);
countryMap.put(“GW”、“AF”);
countryMap.put(“GQ”、“AF”);
国家地图。放置(“GY”、“S”);
countryMap.put(“HT”、“S”);
countryMap.put(“HN”、“S”);
国家地图。put(“HN”、“E”);
国家地图。放置(“IE”、“AS”);
countryMap.put(“BV”、“ANT”);
countryMap.put(“CX”、“O”);
国家地图。put(“HM”、“ANT”);
国家地图。放置(“AF”、“O”);
countryMap.put(“IM”、“E”);
countryMap.put(“RE”、“AF”);
countryMap.put(“KY”、“S”);
countryMap.put(“CC”、“O”);
国家地图。放置(“CK”、“O”);
国家地图.put(“FO”、“E”);
countryMap.put(“GS”、“ANT”);
countryMap.put(“FK”、“S”);
国家地图(下称“MP”、“O”);
国家地图。put(“MH”、“O”);
国家地图;
countryMap.put(“PN”、“S”);
国家地图。放置(“SB”、“O”);
countryMap.put(“TC”、“S”);
countryMap.put(“VG”、“S”);
countryMap.put(“VI”、“S”);
countryMap.put(“ID”、“AS”);
countryMap.put(“IR”、“AS”);
countryMap.put(“IQ”、“AS”);
国家地图;
countryMap.put(“IS”、“E”);
countryMap.put(“IL”、“AS”);
countryMap.put(“IT”、“E”);
countryMap.put(“IN”、“AS”);
countryMap.put(“JM”、“S”);
countryMap.put(“JP”、“AS”);
国家地图.put(“JE”、“E”);
countryMap.put(“JO”、“AS”);
countryMap.put(“KZ”、“AS”);
国家地图。put(“KE”、“AF”);
国家地图。put(“千克”、“AS”);
国家地图;
countryMap.put(“KW”、“AS”);
countryMap.put(“LA”、“AS”);
countryMap.put(“LV”、“E”);
countryMap.put(“LR”、“AF”);
countryMap.put(“LI”、“E”);
国家地图。放置(“LT”、“E”);
countryMap.put(“LB”、“AS”);
countryMap.put(“LY”、“AF”);
国家地图。put(“LU”、“E”);
国家地图。put(“MK”、“E”);
countryMap.put(“MG”、“AF”);
countryMap.put(“MW”、“AF”);
countryMap.put(“MV”、“AS”);
countryMap.put(“ML”、“AF”);
国家地图。put(“MT”、“E”);
countryMap.put(“MA”、“AF”);
countryMap.put(“MQ”、“S”);
国家地图。put(“MU”、“AF”);
countryMap.put(“MR”、“AF”);
国家地图。put(“YT”、“AF”);
countryMap.put(“MX”、“N”);
国家地图。put(“FM”、“O”);
countryMap.put(“MZ”、“AF”);
countryMap.put(“MD”、“E”);
countryMap.put(“MN”、“AS”);
国家地图。把(“我”、“E”);
countryMap.put(“MS”、“S”);
countryMap.put(“MC”、“E”);
countryMap.put(“MM”、“AS”);
countryMap.put(“NA”、“AF”);
国家地图(下称“NR”、“O”);
countryMap.put(“NP”、“AS”);
countryMap.put(“NI”、“S”);
乡村地图
countryPerContinent = @{@"AF":@"AS",
@"AL":@"E",
@"DE":@"E",
@"DZ":@"E",
@"AD":@"E",
@"AQ":@"ANT",
@"AG":@"S",
@"SA":@"AS",
@"AR":@"S",
@"AM":@"AS",
@"AW":@"S",
@"AU":@"O",
@"AZ":@"AS",
@"AT":@"E",
@"BS":@"S",
@"BH":@"AS",
@"BD":@"AS",
@"BB":@"S",
@"BZ":@"S",
@"BJ":@"AF",
@"BM":@"S",
@"BE":@"E",
@"BT":@"AS",
@"BO":@"S",
@"BW":@"AF",
@"BA":@"E",
@"BR":@"S",
@"BN":@"AS",
@"BG":@"E",
@"BF":@"AF",
@"BI":@"AF",
@"KH":@"AS",
@"CM":@"AF",
@"CA":@"N",
@"CV":@"AF",
@"BQ":@"S",
@"AF":@"AS",
@"CO":@"S",
@"KM":@"AF",
@"CG":@"AF",
@"CD":@"AF",
@"KP":@"AS",
@"KR":@"AS",
@"CR":@"S",
@"CI":@"AF",
@"HR":@"E",
@"CU":@"S",
@"CW":@"S",
@"DK":@"E",
@"DJ":@"AF",
@"DM":@"S",
@"EG":@"AF",
@"SV":@"S",
@"EC":@"S",
@"ER":@"AF",
@"SK":@"E",
@"SI":@"E",
@"ES":@"AF",
@"US":@"N",
@"EE":@"E",
@"ET":@"AF",
@"FJ":@"O",
@"PH":@"AS",
@"FI":@"E",
@"FR":@"E",
@"GA":@"AF",
@"GM":@"AF",
@"GE":@"E",
@"GH":@"AF",
@"GI":@"E",
@"GD":@"S",
@"GL":@"N",
@"GP":@"S",
@"GF":@"S",
@"GU":@"AF",
@"GT":@"S",
@"GG":@"E",
@"GN":@"AF",
@"GW":@"AF",
@"GQ":@"AF",
@"GY":@"S",
@"HT":@"S",
@"HN":@"S",
@"HU":@"E",
@"IE":@"AS",
@"BV":@"ANT",
@"CX":@"O",
@"HM":@"ANT",
@"AF":@"O",
@"IM":@"E",
@"RE":@"AF",
@"KY":@"S",
@"CC":@"O",
@"CK":@"O",
@"FO":@"E",
@"GS":@"ANT",
@"FK":@"S",
@"MP":@"O",
@"MH":@"O",
@"UM":@"O",
@"PN":@"S",
@"SB":@"O",
@"TC":@"S",
@"VG":@"S",
@"VI":@"S",
@"ID":@"AS",
@"IR":@"AS",
@"IQ":@"AS",
@"IE":@"E",
@"IS":@"E",
@"IL":@"AS",
@"IT":@"E",
@"IN":@"AS",
@"JM":@"S",
@"JP":@"AS",
@"JE":@"E",
@"JO":@"AS",
@"KZ":@"AS",
@"KE":@"AF",
@"KG":@"AS",
@"KI":@"O",
@"KW":@"AS",
@"LA":@"AS",
@"LV":@"E",
@"LR":@"AF",
@"LI":@"E",
@"LT":@"E",
@"LB":@"AS",
@"LY":@"AF",
@"LU":@"E",
@"MK":@"E",
@"MG":@"AF",
@"MW":@"AF",
@"MV":@"AS",
@"ML":@"AF",
@"MT":@"E",
@"MA":@"AF",
@"MQ":@"S",
@"MU":@"AF",
@"MR":@"AF",
@"YT":@"AF",
@"MX":@"N",
@"FM":@"O",
@"MZ":@"AF",
@"MD":@"E",
@"MN":@"AS",
@"ME":@"E",
@"MS":@"S",
@"MC":@"E",
@"MM":@"AS",
@"NA":@"AF",
@"NR":@"O",
@"NP":@"AS",
@"NI":@"S",
@"NG":@"AF",
@"NU":@"O",
@"NE":@"AF",
@"NO":@"E",
@"NC":@"O",
@"NZ":@"O",
@"OM":@"AS",
@"NL":@"E",
@"PK":@"AS",
@"PW":@"O",
@"PS":@"AS",
@"PA":@"S",
@"PG":@"O",
@"PY":@"S",
@"PE":@"S",
@"PF":@"O",
@"PL":@"E",
@"PT":@"E",
@"PR":@"S",
@"QA":@"AS",
@"HK":@"AS",
@"MO":@"AS",
@"GB":@"E",
@"CF":@"E",
@"DO":@"S",
@"CZ":@"E",
@"ZA":@"AF",
@"RO":@"E",
@"RU":@"E",
@"RW":@"AF",
@"UM":@"S",
@"KN":@"S",
@"SH":@"AF",
@"LC":@"S",
@"MF":@"S",
@"VC":@"S",
@"PM":@"N",
@"WS":@"O",
@"AS":@"O",
@"SM":@"E",
@"EH":@"AF",
@"ST":@"AF",
@"SN":@"AF",
@"SC":@"AF",
@"RS":@"E",
@"SL":@"AF",
@"SG":@"AS",
@"SR":@"S",
@"SJ":@"E",
@"SZ":@"AF",
@"TJ":@"AS",
@"TH":@"AS",
@"TW":@"AS",
@"TZ":@"AF",
@"IO":@"O",
@"TF":@"O",
@"TL":@"AS",
@"TG":@"AF",
@"TK":@"O",
@"TO":@"O",
@"TT":@"S",
@"TN":@"AF",
@"TM":@"AS",
@"TR":@"AS",
@"TV":@"O",
@"TD":@"AF",
@"UA":@"E",
@"UG":@"AF",
@"AE":@"AS",
@"UY":@"S",
@"UZ":@"AS",
@"VZ":@"O",
@"VA":@"E",
@"VE":@"S",
@"VN":@"AS",
@"WF":@"O",
@"CL":@"S",
@"CN":@"AS",
@"CY":@"E",
@"ZM":@"AF",
@"ZW":@"AF"};