にWebサービス(API)からJSONをデコードするとき、私はエラーを取得:スウィフトJSONエラー:型の値をキャストすることができませんでした '__NSDictionaryM' 'にNSArray'
Could not cast value of type '__NSDictionaryM' (0x1037ad8a8) to 'NSArray' (0x1037ad470).
マイコード:
var kGetURL = "http://bitnami.local/cscart_demo/api/users"
//var kGetURL = "http://localhost/fendy/getjson.php"
var json : Array<AnyObject> = []
override func viewDidLoad() {
super.viewDidLoad()
start()
}
func getData(data : NSData){
//error at this line :
json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! Array<AnyObject>
//error
tableView.reloadData()
}
func start(){
var url : NSURL = NSURL(string: kGetURL)!
var data : NSData = NSData(contentsOfURL: url)!
getData(data)
}
があれば私はhttp://localhost/fendy/getjson.phpにURLを変更して、とてもうまく働いています。
私は私のURLは、Webサービスhttp://localhost/fendy/getjson.phpからhttp://bitnami.local/cscart_demo/api/users
応答である場合は、エラーを取得する:Webサービスhttp://bitnami.local/cscart_demo/api/usersから
[{"id":"17","Name":"KFC","Message":"awesome"},
{"id":"18","Name":"McDonald","Message":"good"},
{"id":"23","Name":"Burger King","Message":"tasty"},
{"id":"38","Name":"Pizza hut","Message":"yummy"},
{"id":"39","Name":"Steak","Message":"very Delicious"}]
は応答:
{"users":
[{"user_id":"4","user_login":"user_4","is_root":"N","timestamp":"1441608048","user_type":"C","status":"A","firstname":"","lastname":"","email":"[email protected]","company":"","company_id":"1","company_name":"Simtech"},
{"user_id":"3","user_login":"customer","is_root":"N","timestamp":"1441604240","user_type":"C","status":"A","firstname":"Customer","lastname":"Customer","email":"[email protected]","company":"Simtech","company_id":"1","company_name":"Simtech"},
{"user_id":"1","user_login":"admin","is_root":"Y","timestamp":"1441604240","user_type":"A","status":"A","firstname":"John","lastname":"Doe","email":"[email protected]","company":"Your company","company_id":"0","company_name":null}],
"params":{"page":1,"items_per_page":"10","sort_order":"asc","sort_by":"name","sort_order_rev":"desc","total_items":"3"}}
私はそれはスタイルが同じであると思うが、なぜありませんURLで作業しています。誰でも助けることができますか?
?それが可能だ?テーブルビューCellforRowIndexPath私は変更:varの情報:AnyObject? = json [indexpath.row]? – fendy