I am new in iOS and I am facing problem regarding to post string containing special character.
My code is like this in DidFinishLoading:
NSXMLParser *myNSXMLParserPostObj=[[NSXMLParser alloc]initWithData:myNSMDataPostFromServer];
myNSXMLParserPostObj.delegate=self;
[myNSXMLParserPostObj parse];
NSLog(@"%@",myNSXMLParserPostObj.parserError);
NSString *responseStringWithEncoded = [[NSString alloc] initWithData: myNSMDataPostFromServer encoding:NSUTF8StringEncoding];
//NSLog(@"Response from Server : %@", responseStringWithEncoded);
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[responseStringWithEncoded dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
serverResponse.attributedText = attrStr;
NSString *Str =serverResponse.text;
NSLog(@"Server Response =%@",Str);
UIAlertView *alert3 = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Complaint Added Successfully"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
For getting data from web service I am using code like this:
loginStatusZone = [[NSString alloc] initWithBytes: [myNSMDatazoneFromServer mutableBytes] length:[myNSMDatazoneFromServer length] encoding:NSUTF8StringEncoding];
NSLog(@"loginStatus =%@",loginStatusZone);
NSError *parseError = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatusZone error:&parseError];
NSLog(@"JSON DICTIONARY = %@",xmlDictionary);
recordResultZone = [xmlDictionary[@"success"] integerValue];
NSLog(@"Success: %ld",(long)recordResultZone);
NSDictionary* Address=[xmlDictionary objectForKey:@"soap:Envelope"];
NSLog(@"Address Dict = %@",Address);
NSDictionary *new =[Address objectForKey:@"soap:Body"];
NSLog(@"NEW DICT =%@",new);
NSDictionary *LoginResponse=[new objectForKey:@"FillZonesNewResponse"];
NSLog(@"Login Response DICT =%@",LoginResponse);
NSDictionary *LoginResult=[LoginResponse objectForKey:@"FillZonesNewResult"];
NSLog(@"Login Result =%@",LoginResult);
if(LoginResult.count>0)
{
NSLog(@"Login Result = %@",LoginResult);
NSLog(@"Login Result Dict =%@",LoginResult);
NSString *teststr =[[NSString alloc] init];
teststr =[LoginResult objectForKey:@"text"];
NSLog(@"Test String Value =%@",teststr);
NSString *string = [LoginResult valueForKey:@"text"];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
zoneresponsedict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
idzonearray=[[NSMutableArray alloc]init];
idzonearray=[zoneresponsedict valueForKey:@"ZoneId"];
NSLog(@"Result Array =%@",idzonearray);
shortnamezonearray=[[NSMutableArray alloc]init];
shortnamezonearray=[zoneresponsedict valueForKey:@"ZoneName"];
NSLog(@"Result Array =%@",shortnamezonearray);
}
If I add special character then it shows me error as
Domain=NSXMLParserErrorDomain Code=111 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 111.)"
How can I post data with special character.
I am adding something like this in Thai language
But I am getting this:
Same with Hindi
Output is getting like this
But when anyone add Thai language using Android or website I get proper text in Thai. Only problem is with this post code.
You will need to write the &<> as follows, just like in an html file: