我最终重新格式化了JSON数据:
{"AD": {"Country":"Andorra"},"AE": {"Country":"United Arab Emirates (???????? ???????? ????????)"},"AF": {"Country":"Afghanistan (?????????)"},"AG": {"Country":"Antigua and Barbuda"},"AI": {"Country":"Anguilla"},"AL": {"Country":"Albania (Shqip?ria)"},"AM": {"Country":"Armenia (????????)"},"AN": {"Country":"Netherlands Antilles"},"AO": {"Country":"Angola"},"AQ": {"Country":"Antarctica"},"AR": {"Country":"Argentina"},"AS": {"Country":"American Samoa"},"AT": {"Country":"Austria (?sterreich)"},"AU": {"Country":"Australia"},"AW": {"Country":"Aruba"},"AX": {"Country":"Aland Islands"},"AZ": {"Country":"Azerbaijan (Az?rbaycan)"},"BA": {"Country":"Bosnia and Herzegovina (Bosna i Hercegovina)"},"BB": {"Country":"Barbados"},"BD": {"Country":"Bangladesh (????????)"},"BE": {"Country":"Belgium (Belgi?)"},"BF": {"Country":"Burkina Faso"},"BG": {"Country":"Bulgaria (����ݧԧѧ�ڧ�)"},"BH": {"Country":"Bahrain (???????)"},"BI": {"Country":"Burundi (Uburundi)"},"BJ": {"Country":"Benin (B��nin)"},"BM": {"Country":"Bermuda"},"BN": {"Country":"Brunei (Brunei Darussalam)"},"BO": {"Country":"Bolivia"},"BR": {"Country":"Brazil (Brasil)"},"BS": {"Country":"Bahamas"},"BT": {"Country":"Bhutan (?????????)"},"BV": {"Country":"Bouvet Island"},"BW": {"Country":"Botswana"},"BY": {"Country":"Belarus (���֧ݧѧ��?���)"},"BZ": {"Country":"Belize"},"CA": {"Country":"Canada"},"CC": {"Country":"Cocos Islands"},"CD": {"Country":"Congo, Democratic Republic of the"},"CF": {"Country":"Central African Republic (R��publique Centrafricaine)"},"CG": {"Country":"Congo"},"CH": {"Country":"Switzerland (Schweiz)"},"CI": {"Country":"C?te d'Ivoire"},"CK": {"Country":"Cook Islands"},"CL": {"Country":"Chile"},"CM": {"Country":"Cameroon (Cameroun)"},"CN": {"Country":"China (�й�)"},"CO": {"Country":"Colombia"},"CR": {"Country":"Costa Rica"},"CS": {"Country":"Serbia and Montenegro (����ҧ�?�� �� ����ߧ� ������)"},"CU": {"Country":"Cuba"},"CV": {"Country":"Cape Verde (Cabo Verde)"},"CX": {"Country":"Christmas Island"},"CY": {"Country":"Cyprus (���ԦЦѦ�?)"},"CZ": {"Country":"Czech Republic (?esko)"},"DE": {"Country":"Germany (Deutschland)"},"DJ": {"Country":"Djibouti"},"DK": {"Country":"Denmark (Danmark)"},"DM": {"Country":"Dominica"},"DO": {"Country":"Dominican Republic"},"DZ": {"Country":"Algeria (???????)"},"EC": {"Country":"Ecuador"},"EE": {"Country":"Estonia (Eesti)"},"EG": {"Country":"Egypt (???)"},"EH": {"Country":"Western Sahara (??????? ???????)"},"ER": {"Country":"Eritrea (Ertra)"},"ES": {"Country":"Spain (Espa?a)"},"ET": {"Country":"Ethiopia (Ityop'iya)"},"FI": {"Country":"Finland (Suomi)"},"FJ": {"Country":"Fiji"},"FK": {"Country":"Falkland Islands"},"FM": {"Country":"Micronesia"},"FO": {"Country":"Faroe Islands"},"FR": {"Country":"France"},"GA": {"Country":"Gabon"},"GB": {"Country":"United Kingdom"},"GD": {"Country":"Grenada"},"GE": {"Country":"Georgia (??????????)"},"GF": {"Country":"French Guiana"},"GG": {"Country":"Guernsey"},"GH": {"Country":"Ghana"},"GI": {"Country":"Gibraltar"},"GL": {"Country":"Greenland"},"GM": {"Country":"Gambia"},"GN": {"Country":"Guinea (Guin��e)"},"GP": {"Country":"Guadeloupe"},"GQ": {"Country":"Equatorial Guinea (Guinea Ecuatorial)"},"GR": {"Country":"Greece (���˦�??)"},"GS": {"Country":"South Georgia and the South Sandwich Islands"},"GT": {"Country":"Guatemala"},"GU": {"Country":"Guam"},"GW": {"Country":"Guinea-Bissau (Guin��-Bissau)"},"GY": {"Country":"Guyana"},"HK": {"Country":"Hong Kong"},"HM": {"Country":"Heard Island and McDonald Islands"},"HN": {"Country":"Honduras"},"HR": {"Country":"Croatia (Hrvatska)"},"HT": {"Country":"Haiti (Ha?ti)"},"HU": {"Country":"Hungary (Magyarorsz��g)"},"ID": {"Country":"Indonesia"},"IE": {"Country":"Ireland"},"IL": {"Country":"Israel (?????)"},"IM": {"Country":"Isle of Man"},"IN": {"Country":"India"},"IO": {"Country":"British Indian Ocean Territory"},"IQ": {"Country":"Iraq (??????)"},"IR": {"Country":"Iran (?????)"},"IS": {"Country":"Iceland (?sland)"},"IT": {"Country":"Italy (Italia)"},"JE": {"Country":"Jersey"},"JM": {"Country":"Jamaica"},"JO": {"Country":"Jordan (??????)"},"JP": {"Country":"Japan (�ձ�)"},"KE": {"Country":"Kenya"},"KG": {"Country":"Kyrgyzstan (�����ԧ�٧��ѧ�)"},"KH": {"Country":"Cambodia (Kampuchea)"},"KI": {"Country":"Kiribati"},"KM": {"Country":"Comoros (Comores)"},"KN": {"Country":"Saint Kitts and Nevis"},"KP": {"Country":"North Korea (??)"},"KR": {"Country":"South Korea (??)"},"KW": {"Country":"Kuwait (??????)"},"KY": {"Country":"Cayman Islands"},"KZ": {"Country":"Kazakhstan (?�ѧ٧�?���ѧ�)"},"LA": {"Country":"Laos (????)"},"LB": {"Country":"Lebanon (?????)"},"LC": {"Country":"Saint Lucia"},"LI": {"Country":"Liechtenstein"},"LK": {"Country":"Sri Lanka"},"LR": {"Country":"Liberia"},"LS": {"Country":"Lesotho"},"LT": {"Country":"Lithuania (Lietuva)"},"LU": {"Country":"Luxembourg (L?tzebuerg)"},"LV": {"Country":"Latvia (Latvija)"},"LY": {"Country":"Libya (?????)"},"MA": {"Country":"Morocco (??????)"},"MC": {"Country":"Monaco"},"MD": {"Country":"Moldova"},"ME": {"Country":"Montenegro (����ߧ� ������)"},"MG": {"Country":"Madagascar (Madagasikara)"},"MH": {"Country":"Marshall Islands"},"MK": {"Country":"Macedonia (���ѧܧ֧է�ߧ�?��)"},"ML": {"Country":"Mali"},"MM": {"Country":"Myanmar (Burma)"},"MN": {"Country":"Mongolia (����ߧԧ�� ���ݧ�)"},"MO": {"Country":"Macao"},"MP": {"Country":"Northern Mariana Islands"},"MQ": {"Country":"Martinique"},"MR": {"Country":"Mauritania (?????????)"},"MS": {"Country":"Montserrat"},"MT": {"Country":"Malta"},"MU": {"Country":"Mauritius"},"MV": {"Country":"Maldives (???????? ???????????)"},"MW": {"Country":"Malawi"},"MX": {"Country":"Mexico (M��xico)"},"MY": {"Country":"Malaysia"},"MZ": {"Country":"Mozambique (Mo?ambique)"},"NA": {"Country":"Namibia"},"NC": {"Country":"New Caledonia"},"NE": {"Country":"Niger"},"NF": {"Country":"Norfolk Island"},"NG": {"Country":"Nigeria"},"NI": {"Country":"Nicaragua"},"NL": {"Country":"Netherlands (Nederland)"},"NO": {"Country":"Norway (Norge)"},"NP": {"Country":"Nepal (?????)"},"NR": {"Country":"Nauru (Naoero)"},"NU": {"Country":"Niue"},"NZ": {"Country":"New Zealand"},"OM": {"Country":"Oman (????)"},"PA": {"Country":"Panama (Panam��)"},"PE": {"Country":"Peru (Per��)"},"PF": {"Country":"French Polynesia"},"PG": {"Country":"Papua New Guinea"},"PH": {"Country":"Philippines (Pilipinas)"},"PK": {"Country":"Pakistan (???????)"},"PL": {"Country":"Poland (Polska)"},"PM": {"Country":"Saint Pierre and Miquelon"},"PN": {"Country":"Pitcairn"},"PR": {"Country":"Puerto Rico"},"PS": {"Country":"Palestinian Territories"},"PT": {"Country":"Portugal"},"PW": {"Country":"Palau (Belau)"},"PY": {"Country":"Paraguay"},"QA": {"Country":"Qatar (???)"},"RE": {"Country":"Reunion"},"RO": {"Country":"Romania (Rom?nia)"},"RS": {"Country":"Serbia (����ҧ�?��)"},"RU": {"Country":"Russia (������ڧ�)"},"RW": {"Country":"Rwanda"},"SA": {"Country":"Saudi Arabia (??????? ??????? ????????)"},"SB": {"Country":"Solomon Islands"},"SC": {"Country":"Seychelles"},"SD": {"Country":"Sudan (???????)"},"SE": {"Country":"Sweden (Sverige)"},"SG": {"Country":"Singapore (Singapura)"},"SH": {"Country":"Saint Helena"},"SI": {"Country":"Slovenia (Slovenija)"},"SJ": {"Country":"Svalbard and Jan Mayen"},"SK": {"Country":"Slovakia (Slovensko)"},"SL": {"Country":"Sierra Leone"},"SM": {"Country":"San Marino"},"SN": {"Country":"Senegal (S��n��gal)"},"SO": {"Country":"Somalia (Soomaaliya)"},"SR": {"Country":"Suriname"},"ST": {"Country":"S?o Tom�� and Pr��ncipe"},"SV": {"Country":"El Salvador"},"SY": {"Country":"Syria (?????)"},"SZ": {"Country":"Swaziland"},"TC": {"Country":"Turks and Caicos Islands"},"TD": {"Country":"Chad (Tchad)"},"TF": {"Country":"French Southern Territories"},"TG": {"Country":"Togo"},"TH": {"Country":"Thailand (??????????????)"},"TJ": {"Country":"Tajikistan (����?�ڧܧڧ����)"},"TK": {"Country":"Tokelau"},"TL": {"Country":"Timor-Leste"},"TM": {"Country":"Turkmenistan (T��rkmenistan)"},"TN": {"Country":"Tunisia (????)"},"TO": {"Country":"Tonga"},"TR": {"Country":"Turkey (T��rkiye)"},"TT": {"Country":"Trinidad and Tobago"},"TV": {"Country":"Tuvalu"},"TW": {"Country":"Taiwan (̨��)"},"TZ": {"Country":"Tanzania"},"UA": {"Country":"Ukraine (���ܧ��?�ߧ�)"},"UG": {"Country":"Uganda"},"UM": {"Country":"United States minor outlying islands"},"US": {"Country":"United States"},"UY": {"Country":"Uruguay"},"UZ": {"Country":"Uzbekistan (O'zbekiston)"},"VA": {"Country":"Vatican City (Citt�� del Vaticano)"},"VC": {"Country":"Saint Vincent and the Grenadines"},"VE": {"Country":"Venezuela"},"VG": {"Country":"Virgin Islands, British"},"VI": {"Country":"Virgin Islands, U.S."},"VN": {"Country":"Vietnam (Vi?t Nam)"},"VU": {"Country":"Vanuatu"},"WF": {"Country":"Wallis and Futuna"},"WS": {"Country":"Samoa"},"YE": {"Country":"Yemen (?????)"},"YT": {"Country":"Mayotte"},"ZA": {"Country":"South Africa"},"ZM": {"Country":"Zambia"},"ZW": {"Country":"Zimbabwe"}}
这样做效果更好。
你有一个数组,所以你必须使用foreach循环搜索数组,然后你可以检查字符串并打印结果
foreach($countryCodes->Codes as $Codes) if($Codes->Code == "IT") echo "Code: ".$Codes->Code." - Country: ".$Codes->Country."\n";
如果需要,可以使用break或使用for循环来停止数组中的搜索。
啊,你必须改变第一个和最后一个“进入”
foreach($countryCodes->Codes as $code) { $i = 0; echo $code->Code; $i++; }
这就是如何将它们全部打印出来的。