신속하게 json을 어떻게 구문 분석합니까?

레일리

json국가에 대한 파일 있고 키워드 country를 사용하여 구문 분석하고 싶습니다. 내가 스위프트를 처음 사용하고 정말 더 배우고 싶기 때문에 도와주세요. 감사합니다.

[
    {"country":"Afghanistan","code":"AF"},{"country":"\u00c5land Islands","code":"AX"},
    {"country":"Albania","code":"AL"},
    {"country":"Algeria","code":"DZ"},
    {"country":"American Samoa","code":"AS"},
    {"country":"AndorrA","code":"AD"},
    {"country":"Angola","code":"AO"},
    {"country":"Anguilla","code":"AI"},
    {"country":"Antarctica","code":"AQ"},
    {"country":"Antigua and Barbuda","code":"AG"},
    {"country":"Argentina","code":"AR"},
    {"country":"Armenia","code":"AM"},
    {"country":"Aruba","code":"AW"},
    {"country":"Australia","code":"AU"},
    {"country":"Austria","code":"AT"},
    {"country":"Azerbaijan","code":"AZ"},
    {"country":"Bahamas","code":"BS"},
    {"country":"Bahrain","code":"BH"},
    {"country":"Bangladesh","code":"BD"},
    {"country":"Barbados","code":"BB"},
    {"country":"Belarus","code":"BY"},
    {"country":"Belgium","code":"BE"},
    {"country":"Belize","code":"BZ"},
    {"country":"Benin","code":"BJ"},
    {"country":"Bermuda","code":"BM"},
    {"country":"Bhutan","code":"BT"},
    {"country":"Bolivia","code":"BO"},
    {"country":"Bosnia and Herzegovina","code":"BA"},
    {"country":"Botswana","code":"BW"},
    {"country":"Bouvet Island","code":"BV"},
    {"country":"Brazil","code":"BR"},
    {"country":"British Indian Ocean Territory","code":"IO"},
    {"country":"Brunei Darussalam","code":"BN"},
    {"country":"Bulgaria","code":"BG"},
    {"country":"Burkina Faso","code":"BF"},
    {"country":"Burundi","code":"BI"},
    {"country":"Cambodia","code":"KH"},
    {"country":"Cameroon","code":"CM"},
    {"country":"Canada","code":"CA"},
    {"country":"Cape Verde","code":"CV"},
    {"country":"Cayman Islands","code":"KY"},
    {"country":"Central African Republic","code":"CF"},{"country":"Chad","code":"TD"},
    {"country":"Chile","code":"CL"},
    {"country":"China","code":"CN"},
    {"country":"Christmas Island","code":"CX"},
    {"country":"Cocos (Keeling) Islands","code":"CC"},{"country":"Colombia","code":"CO"},
    {"country":"Comoros","code":"KM"},
    {"country":"Congo","code":"CG"},
    {"country":"Congo, The Democratic Republic of the","code":"CD"},
    {"country":"Cook Islands","code":"CK"},
    {"country":"Costa Rica","code":"CR"},
    {"country":"Cote D\"Ivoire","code":"CI"},
    {"country":"Croatia","code":"HR"},
    {"country":"Cuba","code":"CU"},
    {"country":"Cyprus","code":"CY"},
    {"country":"Czech Republic","code":"CZ"},
    {"country":"Denmark","code":"DK"},
    {"country":"Djibouti","code":"DJ"},
    {"country":"Dominica","code":"DM"},
    {"country":"Dominican Republic","code":"DO"},
    {"country":"Ecuador","code":"EC"},
    {"country":"Egypt","code":"EG"},
    {"country":"El Salvador","code":"SV"},
    {"country":"Equatorial Guinea","code":"GQ"},{"country":"Eritrea","code":"ER"},{"country":"Estonia","code":"EE"},{"country":"Ethiopia","code":"ET"},{"country":"Falkland Islands (Malvinas)","code":"FK"},{"country":"Faroe Islands","code":"FO"},{"country":"Fiji","code":"FJ"},{"country":"Finland","code":"FI"},{"country":"France","code":"FR"},{"country":"French Guiana","code":"GF"},{"country":"French Polynesia","code":"PF"},{"country":"French Southern Territories","code":"TF"},{"country":"Gabon","code":"GA"},{"country":"Gambia","code":"GM"},{"country":"Georgia","code":"GE"},{"country":"Germany","code":"DE"},{"country":"Ghana","code":"GH"},{"country":"Gibraltar","code":"GI"},{"country":"Greece","code":"GR"},{"country":"Greenland","code":"GL"},{"country":"Grenada","code":"GD"},{"country":"Guadeloupe","code":"GP"},{"country":"Guam","code":"GU"},{"country":"Guatemala","code":"GT"},{"country":"Guernsey","code":"GG"},{"country":"Guinea","code":"GN"},{"country":"Guinea-Bissau","code":"GW"},{"country":"Guyana","code":"GY"},{"country":"Haiti","code":"HT"},{"country":"Heard Island and Mcdonald Islands","code":"HM"},{"country":"Holy See (Vatican City State)","code":"VA"},{"country":"Honduras","code":"HN"},{"country":"Hong Kong","code":"HK"},{"country":"Hungary","code":"HU"},{"country":"Iceland","code":"IS"},{"country":"India","code":"IN"},{"country":"Indonesia","code":"ID"},{"country":"Iran, Islamic Republic Of","code":"IR"},{"country":"Iraq","code":"IQ"},{"country":"Ireland","code":"IE"},{"country":"Isle of Man","code":"IM"},{"country":"Israel","code":"IL"},{"country":"Italy","code":"IT"},{"country":"Jamaica","code":"JM"},{"country":"Japan","code":"JP"},{"country":"Jersey","code":"JE"},{"country":"Jordan","code":"JO"},{"country":"Kazakhstan","code":"KZ"},{"country":"Kenya","code":"KE"},{"country":"Kiribati","code":"KI"},{"country":"Korea, Democratic People\"S Republic of","code":"KP"},{"country":"Korea, Republic of","code":"KR"},{"country":"Kuwait","code":"KW"},{"country":"Kyrgyzstan","code":"KG"},{"country":"Lao People\"S Democratic Republic","code":"LA"},{"country":"Latvia","code":"LV"},{"country":"Lebanon","code":"LB"},{"country":"Lesotho","code":"LS"},{"country":"Liberia","code":"LR"},{"country":"Libyan Arab Jamahiriya","code":"LY"},{"country":"Liechtenstein","code":"LI"},{"country":"Lithuania","code":"LT"},{"country":"Luxembourg","code":"LU"},{"country":"Macao","code":"MO"},{"country":"Macedonia, The Former Yugoslav Republic of","code":"MK"},{"country":"Madagascar","code":"MG"},{"country":"Malawi","code":"MW"},{"country":"Malaysia","code":"MY"},{"country":"Maldives","code":"MV"},{"country":"Mali","code":"ML"},{"country":"Malta","code":"MT"},{"country":"Marshall Islands","code":"MH"},{"country":"Martinique","code":"MQ"},{"country":"Mauritania","code":"MR"},{"country":"Mauritius","code":"MU"},{"country":"Mayotte","code":"YT"},{"country":"Mexico","code":"MX"},{"country":"Micronesia, Federated States of","code":"FM"},{"country":"Moldova, Republic of","code":"MD"},{"country":"Monaco","code":"MC"},{"country":"Mongolia","code":"MN"},{"country":"Montserrat","code":"MS"},{"country":"Morocco","code":"MA"},{"country":"Mozambique","code":"MZ"},{"country":"Myanmar","code":"MM"},{"country":"Namibia","code":"NA"},{"country":"Nauru","code":"NR"},{"country":"Nepal","code":"NP"},{"country":"Netherlands","code":"NL"},{"country":"Netherlands Antilles","code":"AN"},{"country":"New Caledonia","code":"NC"},{"country":"New Zealand","code":"NZ"},{"country":"Nicaragua","code":"NI"},{"country":"Niger","code":"NE"},{"country":"Nigeria","code":"NG"},{"country":"Niue","code":"NU"},{"country":"Norfolk Island","code":"NF"},{"country":"Northern Mariana Islands","code":"MP"},{"country":"Norway","code":"NO"},{"country":"Oman","code":"OM"},{"country":"Pakistan","code":"PK"},{"country":"Palau","code":"PW"},{"country":"Palestinian Territory, Occupied","code":"PS"},{"country":"Panama","code":"PA"},{"country":"Papua New Guinea","code":"PG"},{"country":"Paraguay","code":"PY"},{"country":"Peru","code":"PE"},{"country":"Philippines","code":"PH"},{"country":"Pitcairn","code":"PN"},{"country":"Poland","code":"PL"},{"country":"Portugal","code":"PT"},{"country":"Puerto Rico","code":"PR"},{"country":"Qatar","code":"QA"},{"country":"Reunion","code":"RE"},{"country":"Romania","code":"RO"},{"country":"Russian Federation","code":"RU"},{"country":"RWANDA","code":"RW"},{"country":"Saint Helena","code":"SH"},{"country":"Saint Kitts and Nevis","code":"KN"},{"country":"Saint Lucia","code":"LC"},{"country":"Saint Pierre and Miquelon","code":"PM"},{"country":"Saint Vincent and the Grenadines","code":"VC"},{"country":"Samoa","code":"WS"},{"country":"San Marino","code":"SM"},{"country":"Sao Tome and Principe","code":"ST"},{"country":"Saudi Arabia","code":"SA"},{"country":"Senegal","code":"SN"},{"country":"Serbia and Montenegro","code":"CS"},{"country":"Seychelles","code":"SC"},{"country":"Sierra Leone","code":"SL"},{"country":"Singapore","code":"SG"},{"country":"Slovakia","code":"SK"},{"country":"Slovenia","code":"SI"},{"country":"Solomon Islands","code":"SB"},{"country":"Somalia","code":"SO"},{"country":"South Africa","code":"ZA"},{"country":"South Georgia and the South Sandwich Islands","code":"GS"},{"country":"Spain","code":"ES"},{"country":"Sri Lanka","code":"LK"},{"country":"Sudan","code":"SD"},{"country":"Suriname","code":"SR"},{"country":"Svalbard and Jan Mayen","code":"SJ"},{"country":"Swaziland","code":"SZ"},{"country":"Sweden","code":"SE"},{"country":"Switzerland","code":"CH"},{"country":"Syrian Arab Republic","code":"SY"},{"country":"Taiwan","code":"TW"},{"country":"Tajikistan","code":"TJ"},{"country":"Tanzania, United Republic of","code":"TZ"},{"country":"Thailand","code":"TH"},{"country":"Timor-Leste","code":"TL"},{"country":"Togo","code":"TG"},{"country":"Tokelau","code":"TK"},{"country":"Tonga","code":"TO"},{"country":"Trinidad and Tobago","code":"TT"},{"country":"Tunisia","code":"TN"},{"country":"Turkey","code":"TR"},{"country":"Turkmenistan","code":"TM"},{"country":"Turks and Caicos Islands","code":"TC"},{"country":"Tuvalu","code":"TV"},{"country":"Uganda","code":"UG"},{"country":"Ukraine","code":"UA"},{"country":"United Arab Emirates","code":"AE"},{"country":"United Kingdom","code":"GB"},{"country":"United States","code":"US"},{"country":"United States Minor Outlying Islands","code":"UM"},{"country":"Uruguay","code":"UY"},{"country":"Uzbekistan","code":"UZ"},{"country":"Vanuatu","code":"VU"},{"country":"Venezuela","code":"VE"},{"country":"Viet Nam","code":"VN"},{"country":"Virgin Islands, British","code":"VG"},{"country":"Virgin Islands, U.S.","code":"VI"},
    {"country":"Wallis and Futuna","code":"WF"},
    {"country":"Western Sahara","code":"EH"},
    {"country":"Yemen","code":"YE"},{"country":"Zambia","code":"ZM"},
    {"country":"Zimbabwe","code":"ZW"}
]
Vadian

JSON 문자열은 유형의 사전을 포함하는 배열입니다. [String:String]

  • 가져 오기 NSData문자열의 표현을

    let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
    
  • 데이터를 Swift 배열로 역 직렬화

    let json = try! NSJSONSerialization.JSONObjectWithData(data, options: []) as! [[String:String]]
    
  • map함수를 사용하여 모든 국가 값 가져 오기

    let countries = json.map{ $0["country"]! }
    

네트워크에서 문자열을 받으면 적절한 오류 처리를 추가해야합니다.

if let data = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
  do { 
     let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as! [[String:String]]
     let countries = json.map{ $0["country"]! }
  } catch let error as NSError {
     print(error)
  }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

어떻게 GSON를 사용하여 JSON 파일을 구문 분석합니까?

분류에서Dev

boost :: karma / qi로 datetime을 어떻게 구문 분석합니까?

분류에서Dev

PKCS1을 어떻게 구문 분석합니까?

분류에서Dev

Scriban에서 부울을 어떻게 구문 분석합니까?

분류에서Dev

Objective C이 NSString을 어떻게 구문 분석합니까?

분류에서Dev

이 XML 조각을 어떻게 구문 분석합니까?

분류에서Dev

이 XML 조각을 어떻게 구문 분석합니까?

분류에서Dev

Typoscript 파일을 어떻게 구문 분석합니까?

분류에서Dev

Merriam-Webster API의 JSON 응답을 어떻게 구문 분석합니까?

분류에서Dev

ColdFusion CFC에서 JSON 반환을 어떻게 구문 분석합니까?

분류에서Dev

이런 종류의 JSON을 어떻게 구문 분석해야합니까?

분류에서Dev

Eclipse에서 HTML 태그로 주석을 어떻게 구문 분석합니까?

분류에서Dev

우분투에서이 URL을 어떻게 구문 분석합니까?

분류에서Dev

익스프레스 서버의 요청 본문에서 JSON 속성을 어떻게 구문 분석합니까?

분류에서Dev

평가 및 구문 분석을 피하려면 어떻게해야합니까?

분류에서Dev

숫자 구문 분석을 제어하기 위해 CsvHelper 모델 속성을 어떻게 지정합니까?

분류에서Dev

Powershell에서이 문자열을 어떻게 구문 분석합니까?

분류에서Dev

이 XML 문자열을 PHP로 어떻게 구문 분석합니까?

분류에서Dev

JSON을 올바르게 구문 분석하려면 어떻게해야합니까?

분류에서Dev

이 json을 올바르게 구문 분석하려면 어떻게해야합니까?

분류에서Dev

신속하게 HTML로 Json을 구문 분석하는 방법

분류에서Dev

이 JSON 결과를 객체로 어떻게 구문 분석합니까?

분류에서Dev

JavaScript에서 JSON 객체를 어떻게 구문 분석합니까?

분류에서Dev

node.js에서 json arraylist를 어떻게 구문 분석합니까?

분류에서Dev

Flask에서 내 HTML 파일을 어떻게 구문 분석합니까?

분류에서Dev

node.js에서 큰 TSV 파일을 어떻게 구문 분석합니까?

분류에서Dev

datetime (python)으로 이것을 어떻게 구문 분석합니까?

분류에서Dev

Java에서 이것을 어떻게 구문 분석해야합니까?

분류에서Dev

Java에서 이것을 어떻게 구문 분석해야합니까?

Related 관련 기사

  1. 1

    어떻게 GSON를 사용하여 JSON 파일을 구문 분석합니까?

  2. 2

    boost :: karma / qi로 datetime을 어떻게 구문 분석합니까?

  3. 3

    PKCS1을 어떻게 구문 분석합니까?

  4. 4

    Scriban에서 부울을 어떻게 구문 분석합니까?

  5. 5

    Objective C이 NSString을 어떻게 구문 분석합니까?

  6. 6

    이 XML 조각을 어떻게 구문 분석합니까?

  7. 7

    이 XML 조각을 어떻게 구문 분석합니까?

  8. 8

    Typoscript 파일을 어떻게 구문 분석합니까?

  9. 9

    Merriam-Webster API의 JSON 응답을 어떻게 구문 분석합니까?

  10. 10

    ColdFusion CFC에서 JSON 반환을 어떻게 구문 분석합니까?

  11. 11

    이런 종류의 JSON을 어떻게 구문 분석해야합니까?

  12. 12

    Eclipse에서 HTML 태그로 주석을 어떻게 구문 분석합니까?

  13. 13

    우분투에서이 URL을 어떻게 구문 분석합니까?

  14. 14

    익스프레스 서버의 요청 본문에서 JSON 속성을 어떻게 구문 분석합니까?

  15. 15

    평가 및 구문 분석을 피하려면 어떻게해야합니까?

  16. 16

    숫자 구문 분석을 제어하기 위해 CsvHelper 모델 속성을 어떻게 지정합니까?

  17. 17

    Powershell에서이 문자열을 어떻게 구문 분석합니까?

  18. 18

    이 XML 문자열을 PHP로 어떻게 구문 분석합니까?

  19. 19

    JSON을 올바르게 구문 분석하려면 어떻게해야합니까?

  20. 20

    이 json을 올바르게 구문 분석하려면 어떻게해야합니까?

  21. 21

    신속하게 HTML로 Json을 구문 분석하는 방법

  22. 22

    이 JSON 결과를 객체로 어떻게 구문 분석합니까?

  23. 23

    JavaScript에서 JSON 객체를 어떻게 구문 분석합니까?

  24. 24

    node.js에서 json arraylist를 어떻게 구문 분석합니까?

  25. 25

    Flask에서 내 HTML 파일을 어떻게 구문 분석합니까?

  26. 26

    node.js에서 큰 TSV 파일을 어떻게 구문 분석합니까?

  27. 27

    datetime (python)으로 이것을 어떻게 구문 분석합니까?

  28. 28

    Java에서 이것을 어떻게 구문 분석해야합니까?

  29. 29

    Java에서 이것을 어떻게 구문 분석해야합니까?

뜨겁다태그

보관