IOS学习--- Swift JSON解析

var feedbackSurveyJSON:JSON!
let jsonData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource(FEEDBACK_FILE_NAME, ofType: "")!)
        let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.MutableContainers, error: nil)
        feedbackSurveyJSON = JSON(jsonObject)

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("FEEDBACK_CELL", forIndexPath: indexPath) as! UITableViewCell
        var cellLabel = cell.contentView.viewWithTag(CELL_TAG_LBL) as! UILabel
        var cellbutton = cell.contentView.viewWithTag(CELL_TAG_BTN) as! UIButton
        if let questionAnswer = feedbackSurveyJSON[FEEDBACK_KEY_QUESTIONS][indexPath.section][FEEDBACK_KEY_ANSWER][indexPath.row].string{
            cellLabel.text = questionAnswer
        }
        if feedbackSurveyAnswers[indexPath.section][FEEDBACK_KEY_ANSWER]?.integerValue == indexPath.row{
            cellbutton.hidden = false
            cellLabel.font = UIFont(name: "STHeitiSC-Medium", size: 17)
            cell.contentView.backgroundColor = UIColor(red: 247.0/255, green: 235.0/255, blue: 219.0/255, alpha: 1)
        }
        else{
            cellbutton.hidden = true
            cellLabel.font = UIFont(name: "STHeitiSC-Light", size: 17)
            cell.contentView.backgroundColor = ColorConsts.lightYellow
        }
        return cell
    }

猜你喜欢

转载自blog.csdn.net/MickeyChen_/article/details/45641407
今日推荐