我正在尝试使用Alamofire4.0和swift 3.0来调用获取Web服务,但它总是显示我无效的json错误,但是当我在postamn中测试相同的api时显示完美的响应我也验证了json和所有在线表格经过验证。
我找到了调用
Alamofire.request(apiURLStr, method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseString { (responseObject) in
var jsonString = responseObject.result.value
jsonString = jsonString?.replacingOccurrences(of: "\n", with: "")
}
我必须更换" \ n"手动,但我希望这个内置和序列化json数据,如postman。
这是我从Alamofire获得的json:
\n{\n \"id\": 22,\n \"category\": 4,\n \"heading\": \"Sebastian Vettel wins tense Bahrain Grand Prix, Lewis Hamilton second\",\n \"subHeading\" : \"Sebastian Vettel claimed the outright lead of the Formula One championship by winning a tense Bahrain Grand Prix, despite a late charge from Lewis Hamilton.\",\n \"text\" : \"SAKHIR, Bahrain -- Sebastian Vettel claimed the outright lead of the Formula One championship by winning a tense Bahrain Grand Prix, despite a late charge from Lewis Hamilton.\",\n \"picture\" : \"http://www.sebastianvettel.de/images/Galerie-Modul/2017/2017-04-30-GP-Russland.jpg\",\n \"company\" : \"Ferrari\",\n \"author\" : \"Neil\",\n \"published\" : \"2017-04-19 20:20:22\", \n \"updated\" : \"2017-04-19 20:20:22\",\n \"visible\" : \"Y\" \n}
提前致谢