1.数组到json字符串$myArray=array("id"=>"abc","name"=>"hellowoody");echojson_encode($myArray);输出结果为{id:'abc',name:'hellowoody'}2.jsonstringtoarrayobject$jsonObj=json_decode("{id:'abc',name:'hellowoody'}");结果是echo$jsonObj->id;echo$jsonObj->name;3。将sql查询结果转成json对象在php中,查询表返回的结果是array数组类型,使用json_encode方法将返回结果转成json字符串$sql="querydata";$query=$this->db->query($sql);$this->output->set_output(json_encode($query->result()));
