如何在没有密钥的情况下解码JSON值?

时间:2014-02-07 07:03:08

标签: 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/

4 个答案:

答案 0 :(得分:3)

蹩脚的回答:)

$json = '{"http://www.google.com/","http://www.facebook.com/","http://www.wordpress.com/",0}';
$json = str_replace(array('{', '}'), array('[',']'), $json);
print_r(json_decode($json));

答案 1 :(得分:3)

你可以使用这个功能

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);

输出:

Array
(
    [0] => http://www.google.com/
    [1] => http://www.facebook.com/
    [2] => http://www.wordpress.com/
)

答案 2 :(得分:2)

real JSON开始,代表一组值。

$json = '["http://www.google.com/","http://www.facebook.com/",".."]';

然后使用json_decode

$arr = json_decode($json);
print_r($arr);

答案 3 :(得分:1)

在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>";
   }
  ?>