我是ios编程的新手,我正在尝试解析XML字符串:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SurveyListGetResponse xmlns="http://tempuri.org/"><SurveyListGetResult>{"SurveyList":[{"SurveyID":1,"SurveyName":"SomeSurvey","SurveyDescription":"Clean","BeginDate":"01.01.2013","EndDate":"05.01.2013"}],"Questions":[{"SurveyID":1,"QuestionID":8,"Question":"Mobile Question","AnswerTypeID":2}],"Answers":[{"SurveyID":1,"QuestionID":8,"AnswerID":18,"Answer":"YES"},{"SurveyID":1,"QuestionID":8,"AnswerID":19,"Answer":"Hayör"}]}</SurveyListGetResult></SurveyListGetResponse></soap:Body></soap:Envelope>
这是我的xml字符串,正如你在上面看到的那样,“Answer”中有土耳其字符:“Hayör”,我检查了所有字符串,解析器将一直到“Hay”,但它不是“ör” ”
NSData *xmlData = [responseString dataUsingEncoding:NSWindowsCP1254StringEncoding];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
[xmlParser setDelegate:self];
[xmlParser parse];
这是我的解析器代码,我习惯使用NSWindowsCP1254StringEncoding和NSUTF8StringEncoding。
aftes string将转换为解析器,它正在改变{"SurveyList":[{"SurveyID":1,"SurveyName":"Some Survey","SurveyDescription":"Clean","BeginDate":"01.01.2013","EndDate":"05.01.2013"}],"Questions":[{"SurveyID":1,"QuestionID":8,"Question":"Mobil Soru","AnswerTypeID":2}],"Answers":[{"SurveyID":1,"QuestionID":8,"AnswerID":18,"Answer":"YES"},{"SurveyID":1,"QuestionID":8,"AnswerID":19,"Answer":"Hay
我需要做些什么来解决它?抱歉我的英文不好,谢谢。
答案 0 :(得分:0)
我会尝试将数据传递给解析器作为NSUTF8StringEncoding,然后将其转换为您想要用于土耳其语的任何编码。如果这不起作用,我会尝试使用stringByAddingPercentEscapesUsingEncoding
另外......您是否注意到 SurveyListGetResult 标记中的数据实际上是一个JSON字符串?