json如何转php-PHP问题

资源魔 35 0

json若何转php?

json_decode是php5.2.0之后新增的一个PHP内置函数,其作用是对JSON格局的字符串进行编码.

  json_decode的语法例则:

  json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )

  json_decode承受一个JSON格局的字符串而且把它转换为PHP变量 ,当该参数$assoc为TRUE时,将前往array,不然前往object。

  JSON 格局的字符串

  $json = '{"a":"php","b":"mysql","c":3}';

  此中a为键,php为a的键值。

  实例:

<?php   
$json = '{"a":"php","b":"mysql","c":3}';  
$json_Class=json_decode($json);   
$json_Array=json_decode($json, true);   
print_r($json_Class);   
print_r($json_Array);         
?>

  顺序输入:

  stdClass Object (
  [a] => php
  [b] => mysql
  [c] => 3 )
  Array (
  [a] => php
  [b] => mysql
  [c] => 3 )

  正在下面代码的条件下

  拜访工具类型$json_Class的a的值

echo $json_Class->{'a'};

  顺序输入:php

  拜访数组类型$json_Array的a的值

echo $json_Array['a'];

  顺序输入:php

相干保举:《PHP教程》

以上就是json若何转php的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 json php故障解决 php使用问题

抱歉,评论功能暂时关闭!