Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 513 Bytes

File metadata and controls

30 lines (24 loc) · 513 Bytes

AnyJSON

  1. 使用
let json1 = """
{
  "sites": {
    "id": "1",
    "name": "菜鸟教程",
    "url": "www.runoob.com",
    "lang": {"en": "false", "zn": "true"},
    "address": [
      {"city": "beijing", "province": "null"},
      {"city": "chengdu", "province": "sichuan"}
    ]
  }
}
"""

let data = json1.data(using: .utf8)
let value = try JSONDecoder().decode(AnyJSON.self, from: data!)

print(value.sites.id.intValue)
output: 1

print(value.sites.name.stringValue)
output: 菜鸟教程