Php Swift 2 Json utf8字符串错误

Php Swift 2 Json utf8字符串错误,php,ios,json,swift2,utf8-decode,Php,Ios,Json,Swift2,Utf8 Decode,我有工作的Json文件和应用程序,但我有文本编码问题 我的Json文件输出示例 {"status":"SUCCESS","data":[{"id":"21","title":"I'm working on project","description":"Lorem ipsum dolor sit er elit lamet, consectetaur cilliim adipisicin"}]} Json解析函数,我添加了一些解析函数,您可以在下面看到 func in

我有工作的Json文件和应用程序,但我有文本编码问题

我的Json文件输出示例

{"status":"SUCCESS","data":[{"id":"21","title":"I'm working on project","description":"Lorem ipsum dolor sit er elit lamet, consectetaur cilliim adipisicin"}]}
Json解析函数,我添加了一些解析函数,您可以在下面看到

    func initArrayCategory(){
        self.getResponseFromURL(self.getStringURLWithJSONFormatForUserAPI(URL_API_NEWS_CATEGORIES), withParams: nil, Success: { (operation, responseObject) -> () in
            if let success = responseObject[API_PARAM_STATUS] as? String{
                if success == "SUCCESS"{
                    if let data = responseObject[API_PARAM_DATA] as? NSMutableArray{
                        self.arrayCategory = data
                    }
                }
                self.Category.reloadData()
            }

            }, Failure: { (operation, error) -> () in
                if error.localizedDescription == "The network connection was lost."{
                    self.initArrayCategory()
                }
            }, showLoader: true, hideLoader: true)
    }



    func postResponseFromURL(strURL: String, withParams dictParams:NSDictionary?, Success:(operation: AFHTTPRequestOperation!, responseObject:AnyObject!)->(),Failure:(operation: AFHTTPRequestOperation!, error:NSError!)->(),showLoader isShowDefaultLoader:Bool,showAnimated isShowLoaderAnimated:Bool, hideLoader isHideDefaultLoader:Bool)
    {

        let hudprogress = MBProgressHUD()

        if isShowDefaultLoader{
            MBProgressHUD.showHUDAddedTo(self.view, animated: true)
            hudprogress.mode = MBProgressHUDModeDeterminate
            hudprogress.labelText = "Loading"
        }

        let manager = AFHTTPRequestOperationManager()
        manager.responseSerializer.acceptableContentTypes = NSSet(array: ["text/html", "application/json"]) as Set<NSObject>

        manager.POST(strURL, parameters: dictParams, success: { (operation, responseObject) -> Void in
            //println("RESPONSE DATA: " + responseObject.description)

            if isHideDefaultLoader{
                MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
            }

            Success(operation: operation, responseObject: responseObject
            )

            }) { (operation, error) -> Void in

                print("Response:    \(operation.responseObject)")
                print("Error:  " + error.localizedDescription)

                Failure(operation: operation, error: error)
                hudprogress.hide(true)
        }
    }



let URL_API_HOST:String = "http://www.blabla.com/Items/"

    func postResponseFromURL(strURL: String, withParams dictParams:NSDictionary?, Success:(operation: AFHTTPRequestOperation!, responseObject:AnyObject!)->(),Failure:(operation: AFHTTPRequestOperation!, error:NSError!)->(),showLoader isShowDefaultLoader:Bool, hideLoader isHideDefaultLoader:Bool)
    {
        self.postResponseFromURL(strURL, withParams: dictParams, Success: Success, Failure: Failure, showLoader: isShowDefaultLoader, showAnimated: true, hideLoader: isHideDefaultLoader)
    }


    func setObjectToUserDefaults(object:AnyObject, forKey strKey:String, writeToDisk isWrite:Bool )
    {
        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setObject(object, forKey: strKey)
        if isWrite{
            defaults.synchronize()
        }
    }



    func getStringURLWithJSONFormatForUserAPI(strAPI:String)->String{
        return self.getStringURLForUserAPI(strAPI, withJSONFormat: true)
    }


    func getStringURLForUserAPI(strAPI:String, withJSONFormat isJSON:Bool)->String{

        var strURL:String = self.getBaseURl()
        strURL += strAPI

        if isJSON
        {
            strURL = self.addJSONFormatInURL(strURL)
        }

        return strURL
    }


    func getBaseURl()->String{
        return URL_API_HOST
    }


    func addJSONFormatInURL(strURL:String)->String{
        return strURL + URL_API_FORMAT_JSON
    }
Mysql表Mysql文件

Mysql表中的实际值

('21', 'I&#039;m working on project', 'Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.  ', '7292754.jpg', '', '2', '26')
远程连接Php文件

远程Php文件

输出

一定是

请帮帮我


TY

最后我决定,我认为代码需要太多的人! 谢谢@Eric D。我尝试了你的链接代码,我改变了一些事情,现在工作成功了

代码

if let detailanother =  detailTitle {


            do {
                let encodedData = detailanother.dataUsingEncoding(NSUTF8StringEncoding)!
                let attributedOptions : [String: AnyObject] = [
                    NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                    NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
                ]
                let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
                self.textim.text = attributedString.string
            } catch {
                fatalError("Unhandled error: \(error)")
            }


    }
谢谢大家!
好的编码

显示如何加载JSON文件。它来自哪里?是什么产生了JSON服务器端?确认如果您使用类似curl的方法访问它,实体转义尚未完成,因为如果是,这是一个服务器端问题。我不同意这是AFNetworking的问题,而是您如何使用它,并且对正在发生的事情缺乏了解。例如,如果您希望使用application/json,为什么会有可接受的内容类型text/html,如果您希望使用text/html,那么您应该正确处理它。这不是AFNetworking的问题。我怀疑服务器端。您检查过数据库列中的实际内容吗?数据库是如何填充的?@SwiftDeveloper您需要的是:
('21', 'I&#039;m working on project', 'Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.  ', '7292754.jpg', '', '2', '26')
$db_host="my host";   // your mysql database host name
$db_username="myusername";  // username
$db_pass="my past";                 // password
$connnect=mysql_connect("$db_host","$db_username","$db_pass") or die("Databese Error, Please check your connection values !");  
@mysql_select_db ("App");  // Select Your Database


@mysql_query("SET NAMES utf8");
@mysql_query("SET CHARACTER SET utf8");
@mysql_query("SET COLLATION_CONNECTION = 'utf8_general_ci'");
header("Content-type: application/json; charset=utf-8");
include("connect.php");

$q = "Select * from App";
$r = mysql_query($q) or die(mysql_error());

if(mysql_num_rows($r) > 0) {

    $arr = array();

            while ($row = mysql_fetch_assoc($r))
            {
                $arr[] = $row;
            }
            echo json_encode(array('status'=>"SUCCESS",'data'=>$arr));
        }
        else {
            echo json_encode(array('status'=>"FAIL"));
        }       
textim.text =  I&#039;m working on project
textim.text = I'm working on project

json file coming title = I&#039;m working on project
if let detailanother =  detailTitle {


            do {
                let encodedData = detailanother.dataUsingEncoding(NSUTF8StringEncoding)!
                let attributedOptions : [String: AnyObject] = [
                    NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                    NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
                ]
                let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
                self.textim.text = attributedString.string
            } catch {
                fatalError("Unhandled error: \(error)")
            }


    }