一、json_encode()
该函数主要用来将数组和对象,转换为json格式。...先看一个数组转换的例子:
$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}
由于json只接受utf-8编码的字符,所以json_encode()的参数必须是utf-8编码,否则会得到空字符或者null。...由于javascript不支持关联数组,所以json_encode()只将索引数组(indexed array)转为数组格式,而将关联数组(associative array)转为对象格式。...比如,现在有一个索引数组
$arr = Array('one', 'two', 'three');
echo json_encode($arr);
结果为:
????