简体   繁体   English

如何获取text / html; charset = utf-8响应iOS Objective C中的请求?

[英]How to get text/html; charset=utf-8 in response of request in iOS Objective C?

I send request to server with url. 我将请求发送到带有url的服务器。
When PO my response , "Content-Type" = "text/html; charset=utf-8"; 当我回复PO时,“ Content-Type” =“ text / html; charset = utf-8”;
And now i don't know how to detect and pars this data. 现在,我不知道如何检测和解析此数据。
my code is here : 我的代码在这里:

//Send request
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];    

I have used to use this code for Json: 我曾经为Json使用以下代码:

NSDictionary *backDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil ];

And this code for XML: 这段XML代码:

//Get response from server as XML
backDict = [XMLReader dictionaryForXMLData:data options:XMLReaderOptionsProcessNamespaces
                                                 error:&error];

But does not work any of both. 但是两者都不起作用。
Thanks. 谢谢。

If your response data is html then simply convert that data to string. 如果您的响应数据是html则只需将该数据转换为字符串即可。

NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

And you'll have your response. 您会得到回应。

But you should consider to avoid getting useful data in html, it's hard to parse. 但是您应该考虑避免在html中获取有用的数据,这很难解析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM