PHP
1$db=new PDO($dsn,$dbuser,$dbpass); 2header("Access-Control-Allow-Origin:*"); 3header("Content-Type:application/json;charset=utf-8"); 4$sql="select name,gender,birthday from users where id=:id limit 1"; 5$stmt=$db->prepare($sql); 6$stmt->execute(array(":id"=>"$_POST['id']")); 7$value=$stmt->fetch(); 8echo json_encode($value);
↑このAPIに、
PHP
1$postdata=array("id"=>"uesr_id"); 2$ch=curl_init("http://hogehoge.com/request"); 3curl_setopt($ch, CURLOPT_POST, true); 4curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 5curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); 6$me = curl_exec($ch); 7curl_close($ch);
といった形でIDを送信し、json形式で情報を受け取りたいのですが、返ってきたjsonを配列に直し、ダンプすると、
array(10) {
["id"]=> string(40) "userid"
[0]=> string(40) "userid"
["name"]=> string(8) "username"
[1]=> string(8) "username"
["gender"]=> string(4) "male"
[2]=> string(4) "male"
["birthday"]=> string(10) "2000-01-01"
[3]=> string(10) "2000-01-01"
}
というふうに、連想配列と普通の配列を混ぜたようなものになっていました。これは普通では無いですよね?原因がわかりません。教えて下さい。-人-
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。