如何在swift

时间:2018-03-13 15:38:37

标签: json swift soap

我正在使用SOAP和Swift,我得到了SOAP的响应。但是,响应是字符串类型并包含JSON数组。我在将字符串转换为JSON时遇到问题。

let session = URLSession.shared
let task = session.dataTask(with: request){(data,resp,error) in
    guard error == nil && data != nil else{
        print("connection error or data is nil")

        return
    }

    if resp != nil{
        self.mutableData.length = 0;
    }

    self.mutableData.append(data!)

    let xmlParser = XMLParser(data: self.mutableData as Data)
    xmlParser.delegate = self
    xmlParser.parse()
    xmlParser.shouldResolveExternalEntities = true
}

task.resume()
}

func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
    currentElementName = elementName
}

func parser(_ parser: XMLParser, foundCharacters string: String) {
    if currentElementName.isEqual(to: "GetStudentGradesResult") {
        datas.append(string)
    }
}

func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
}

这是我的SOAP响应字符串:

  

[{“StudentId”:1526,“SchoolCode”:“21013”,“AcademicPeriod”:“2016-2017”,“ClassBranch”:“10-A-LEVEL L”,“CourseId”:1,“CourseName” “:” Matematik “ ”ISNUMBER“:真, ”作业1“:10 ”Midterm1“:9 ”Final1“:9 ”Grade1“:9 ”HomeWork2“:10 ”Midterm2“:8,” Final2 “:8,” Grade2 “:8中,” Notes1 “:NULL,” Notes2 “:NULL,” InstructorIdNumber1 “:” 175023" , “InstructorIdNumber2”: “223153”, “EffortGrade1”:NULL, “EffortGrade2”:空, “LetterGrade1”:null,“LetterGrade2”:null,“UpdateDate”:“2017-07-12T13:42:00”,“StudentNumber”:101,“StudentFullName”:“DOĞATOPRAKİDRİS”,“StudentObject”:{“ StudentId“:1526,”SchoolCode“:”21013“,”SchoolNumber“:101,”FullName“:”DOĞAÇTOPRAKİDRİS“,”ParentIdNumber“:”139206“,”StudentAcademicList“:null}},{”StudentId“: 1526,“SchoolCode”:“21013”,“AcademicPeriod”:“2016-2017”,“ClassBranch”:“10-A-LEVEL L”,“CourseId”:2,“CourseName”:“Fizik”,“IsNumber” :真, “作业1”:7, “Midterm1”:7, “Final1”:7, “Grade1”:7, “HomeWork2”:8中, “Midterm2”:8中, “Final2”:8中, “Grade2”:8 “Notes1”:空, “Notes2”:空, “InstructorIdNumber1”: “165914”,“Instruc torIdNumber2 “:” 168304" , “EffortGrade1”:NULL, “EffortGrade2”:NULL, “LetterGrade1”:NULL, “LetterGrade2”:NULL, “UpdateDate”: “2017-07-12T13:42:00”, “StudentNumber” :101,“StudentFullName”:“DOĞATOPRAKİDRİS”,“StudentObject”:{“StudentId”:1526,“SchoolCode”:“21013”,“SchoolNumber”:101,“FullName”:“DOĞAÇTOPRAKİDRİS”,“ParentIdNumber” “:” 139206" , “StudentAcademicList”:空}}]

0 个答案:

没有答案