【发布时间】:2018-04-20 17:45:51
【问题描述】:
我正在尝试使用 PHP 为中国用户创建一个适配器来连接 GoogleAPI。在 json 响应中,我试图获取描述数据。但是,我什至无法获取字典数据。有什么建议吗?
iOS 代码
Alamofire.request(requestString, method: .post, parameters: data, encoding: URLEncoding.httpBody, headers: [:]).responseJSON { (response) in
switch response.result {
case .success(_):
print(response.result.value)
if let dictionary = response.result.value as? Dictionary<String,Any>{
print("dictionary", dictionary)
}
}
}
PHP
<?php
$post_data = $_POST['data'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://vision.googleapis.com/v1/images:annotate?key=KKEEYY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-length: ".strlen($post_data)));
$result = curl_exec($ch);
echo json_encode($result);
?>
编辑
如果我使用自己的适配器,我可以看到键和值有额外的“”
如果直接向 Google print("direct", response.result.value)请求响应
如果使用我的适配器,请回复print("using adapter", response.result.value)
【问题讨论】:
标签: php ios json swift alamofire