Php 如何在没有密钥的情况下解码JSON值?
我有jsonPhp 如何在没有密钥的情况下解码JSON值?,php,json,Php,Json,我有json {"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0} 我怎样才能像这样打印 http://www.google.com/ http://www.facebook.com/ http://www.wordpress.com/ 看看php中的示例代码 <?php $jsonData = '{ "user":"John", "age":22, "co
{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}
我怎样才能像这样打印
http://www.google.com/
http://www.facebook.com/
http://www.wordpress.com/
看看php中的示例代码
<?php
$jsonData = '{ "user":"John", "age":22, "country":"United States" }';
$phpArray = json_decode($jsonData);
print_r($phpArray);
foreach ($phpArray as $key => $value) {
echo "<p>$key | $value</p>";
}
?>
蹩脚的答案:)
你可以使用这个功能
function getUrls($string) {
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $matches);
//return (array_reverse($matches[0]));
return ($matches[0]);
}
像这样
$json_str = '{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}';
$arr = getUrls($json_str);
echo "<pre>";
print_r($arr);
从实数开始,表示一个值数组
$arr = json_decode($json);
print_r($arr);
然后使用
google json_decode function该示例不是有效的json。我只需要我的项目的url,那么我如何才能使json正确,以便将来能够正确识别/创建json。虽然这个示例有效,但它不适用于OP,因为他/她实际上没有json。。
Array
(
[0] => http://www.google.com/
[1] => http://www.facebook.com/
[2] => http://www.wordpress.com/
)
$json = '["http://www.google.com/","http://www.facebook.com/",".."]';
$arr = json_decode($json);
print_r($arr);