我想通过使用curl来获得一些json结果。但我不想得到所有的结果。我只想从中获得一个特定的参数。所以我该怎么做?使用PHP获取json结果的具体数据使用PHP
这是我的方法:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_URL, "http://sample.jsp?id=123456");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
$parts = parse_str($output);
$memberid = mysqli_real_escape_string($con, $query['memberid ']);
我得到这样的结果:
{"memberid ":"000000000","cardNumber":"111111111","result":"OK"}
但其实我只是想
000000000
请帮忙。
做'json_decode('string',true)'然后用数组索引来读取它。 – 2014-09-22 15:02:12
这里是'json_decode'的链接http://php.net/manual/en/function.json-decode.php – cmorrissey 2014-09-22 15:02:46
你真的在问如何解码JSON吗?或者它实际上是一个关于让服务器只发送部分数据的复杂问题? – 2014-09-22 15:03:31