繁体   English   中英

如何使用下面提到的代码在Swift中序列化JSON请求?

[英]How To Serialise JSON Request in Swift using below mentioned code?

错误:域= NSCocoaErrorDomain代码= 3840“字符0周围的值无效。” UserInfo = {NSDebugDescription =字符周围的值无效

func FAQ(token: String){
    let urlString = BaseURL + "faq?token=" + token
    request(.GET, urlString).responseJSON(options: NSJSONReadingOptions.AllowFragments){(json) -> Void in
        if json.result.error != nil{
            NSNotificationCenter.defaultCenter().postNotificationName(NotifRequestError.FAQ.rawValue, object: json.result.error, userInfo: nil)
            print(json.result.error)
            return
        }

        let responseDict = NSMutableDictionary(dictionary: json.result.value as! NSDictionary)
        print(responseDict)
        NSNotificationCenter.defaultCenter().postNotificationName(NotifRequestSuccess.FAQ.rawValue, object: self, userInfo: ["data": responseDict])
    }
}

请尝试这个

let data = NSKeyedArchiver.archivedDataWithRootObject(urlString)

让newData = NSJSONSerialization.JSONObjectWithData(data !, options:NSJSONReadingOptions(),error:nil)as? NSData让urlStringToPass = NSString(data:newData !,编码:NSUTF8StringEncoding)

请检查邮递员中的回复。 json响应格式正确或不是Bcoz,如果json格式不正确.allowfragment将不起作用。 JSON字符串必须用引号引起来:(有关详细信息,请参见http://www.json.org ):尝试从allow片段到mutablecontainer的Nsjsonreadingoption

暂无
暂无

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

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