0

我想将返回的 JSON 消息从下面的 url 存储到使用 PHP 的某种变量中。

在我的控制器里面我有这个代码:

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.livepicly.com/app/api.php'.$str);
curl_exec($ch);
curl_close($ch);

($str 是一个包含所有必需参数的变量)。

上述网址:

http://www.livepicly.com/app/api.php?method=add_reservation&email=jbond%40example.com&fname=James&lname=Bond&phone=1234561&vid=726&size=2&date=2013-05-31+1%3A15+PM&request=Hi+那里

(上面的url打开时会返回一个JSON消息)

4

2 回答 2

1

您需要退回转账。

<?php

$str = '?method=add_reservation&email=jbond%40example.com&fname=James&lname=Bond&phone=1234561&vid=726&size=2&date=2013-05-31+1%3A15+PM&request=Hi+there';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.livepicly.com/app/api.php'.$str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
var_dump($result->result[0]->message);

?>
于 2013-05-29T04:38:31.280 回答
1
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.livepicly.com/app/api.php'.$str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);

$my_array = json_decode($data,true);  // <-- turns the returned json into an assoc array
$my_obj =  json_decode($data); // <-- or into an object

// {"foo-bar": 12345}
echo $my_array['foo-bar'];   // outputs 12345
echo $my_obj->{'foo-bar'};  // outputs 12345
于 2013-05-29T04:36:18.830 回答