这是我解析 JSON 的方法
var apiUrl = NSURL(string: "http://127.0.0.1/api.php")
var apiData = NSData.dataWithContentsOfURL(apiUrl, options: NSDataReadingOptions.DataReadingUncached, error: nil)
var apiJson = NSJSONSerialization.JSONObjectWithData(apiData, options: NSJSONReadingOptions.AllowFragments, error: nil)
http://127.0.0.1/api.php
url 返回数据。
{
"tit":"服务器",
"loc":[
{
"_name":"北京",
"evn":"funckEvent:"
},{
"_name":"英国",
"evn":"funckEvent:"
},{
"_name":"日本",
"evn":"funckEvent:"
},{
"_name":"发过",
"evn":"funckEvent:"
},{
"_name":"中国",
"evn":"funckEvent:"
}
]
}
如何循环json数组?我想循环打印括号的内容{"_name":"中国","evn":"funckEvent:"}
var loc = apiJson.objectForKey("loc")