応答からJSONを解析しようとしています。しかし、私はこのエラーを持っています
私のコードはです。タイプ '__NSCFString'(0x104a67320)の値を 'NSDictionary'(0x104a68108)にキャストできません
NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) in
if error != nil {
print("error = \(error)")
return
}
do {
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments) as! NSDictionary
let str = json["ResultMsg"] as! NSString
print ("ResultMsg = " + (str as String))
}catch let error as NSError {
print("Error : " + error.localizedDescription)
}
}).resume()
とコンソールログがある: ":\ "SUCCESS \"、\ "ResultMsg \" \" 1 \ "\"( "{\" ResuleCode \オプション
responseString = \ "ユーザーID \:\" 4138 \ "、\"電子メール\ ":\" [email protected] \ "、\"ユーザー名\:\ "テスト1 \"、\ " \ "Phone \":\ "\"、\ "AppKey \":\ "\"、\ "LoginDt \":\ "9/23/2016 1:12:18 PM \ "、\" LogoutDt \ ":\" 9/1/2016 10:36:02 AM \ "、\" RegDt \ ":\" 8/31/2016 9:26: \ "KeyEnabled \"、\ "KeyEnabled \":\ "KeyEnabled \":\ "1 \"、\ " \ "KeywordStartTime \":\ "08:30:00 \"、\ "KeywordEndTime \":\ "15:30:00 \"、\ "FastStartTime \":\ "08:00:00 \"、 \ "FastEndTime \":\ "15:30:00 \"、\ "IsFirst \":\ "NOT_FIR \ "IswordNews \"、\ "IsKeywordNews \"、\ "1 \"、\ "KeywordStartDt \":\ "\"、KeywordEndDt \ ":\" \ "} ]} ")
タイプ '__NSCFString'(0x10abdf320)の値を 'NSDictionary'(0x10abe0108)にキャストできませんでした。
ご協力いただければ幸いです。
ブレークポイントを入れて、このエラーを投げているラインチェックを正確に理由を知らないのですか? –
json = try NSJSONSerialization.JSONObjectWithData(data !, options:.AllowFragments)を! NSDictionary - >この行は問題です.. signal SOGABRT –
@MoonJikLee xcodeレスポンスを表示する代わりに実際のjsonレスポンスを表示できますか? –