PHP--- JSON和数组的转换
一、json_encode()
<?php
$arr =array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
输出
{"a":1,"b":2,"c":3,"d":4,"e":5}
再看一个对象转换的例子:
$obj->body = 'another post';
$obj->id = 21;
$obj->approved = true;
$obj->favorite_count = 1;
$obj->status = NULL;
echo json_encode($obj);