阿拉莫菲尔奇怪的JSON前缀-Swift 2.0

阿拉莫菲尔奇怪的JSON前缀-Swift 2.0,json,swift,prefix,swift2,alamofire,Json,Swift,Prefix,Swift2,Alamofire,我试图从API获取JSON文件,但是Alamofire(分支:Swift 2.0)返回带有奇怪前缀的文件(Alamofire.Result.Success)。如果这是一个愚蠢的问题,我很抱歉,但我是阿拉莫菲尔的新手。我怎样才能得到一个可以与SwiftyJSON一起使用的普通文件 我的代码: func getText (image: UIImage){ let url = "https://api.idolondemand.com/1/api/sync/ocrdocument/v1"

我试图从API获取JSON文件,但是Alamofire(分支:Swift 2.0)返回带有奇怪前缀的文件(Alamofire.Result.Success)。如果这是一个愚蠢的问题,我很抱歉,但我是阿拉莫菲尔的新手。我怎样才能得到一个可以与SwiftyJSON一起使用的普通文件

我的代码:

func getText (image: UIImage){

    let url = "https://api.idolondemand.com/1/api/sync/ocrdocument/v1"
    let apiKey = "xxx-xxx-xxx-xxx-xxx"
    let mode = "document_photo"
    let imageData = UIImagePNGRepresentation(image)

    Alamofire.upload(
        .POST,
        url,
        multipartFormData: { multipartFormData in
            multipartFormData.appendBodyPart(
                data: apiKey.dataUsingEncoding(NSUTF8StringEncoding)!,
                name: "apikey"
            )
            multipartFormData.appendBodyPart(
                data: mode.dataUsingEncoding(NSUTF8StringEncoding)!,
                name: "mode"
            )
            multipartFormData.appendBodyPart(data: imageData!, name: "file",fileName: "image.png", mimeType: "image/png")
        },
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .Success(let upload, _, _):
                upload.responseJSON  { _, _, json in

                        print(JSON)

                }
            case .Failure(let encodingError):
                print(encodingError)
            }
        }
    )
}
打印输出(JSON):

Alamofire.Result.Success([text\u块:(
{
高度=127;
左=0;
text=“\U2022 response()\n\U2022 responseString(编码:NSStringEncoding)\n\U2022 responseJSON(选项:NSJS0NReading0ptions)\n\U2022 responsePropertyList(选项:NSPropertyStread0PTIONS)”;
top=0;
宽度=487;
}
)])

在调用
upload.responseJSON(uuquo:completionHandler:)
的闭包参数中,您指定的名为
json
的参数将作为Alamofire
结果
枚举传递(请参阅)

您应该能够通过访问枚举的
属性来获取该枚举的关联数据,如下所示:

upload.responseJSON  { _, _, json in
  print(json.value!)
}

此外,如果有机会,请查看(一个在Swift中处理JSON的流行库)。

Thx。但是现在,如果我做了
case.Success(let upload,{,}):upload.responseJSON{,{,{,}json在let json=json({u json.data!)中,如果让ocr\u results=json[“text\u block”][0][“text”].string{}
我会在
中得到一个错误,因为{u json.data是nil@NMAC427你想要
\u json.value
如果要从
结果中获取序列化响应。成功
相关数据
upload.responseJSON  { _, _, json in
  print(json.value!)
}