【发布时间】:2014-08-31 11:48:33
【问题描述】:
我有一个关于在 php 中格式化 json 的问题。这是我的代码
公共函数测试() {
if (!empty($_POST)) {
$this->db->select('*');
$this->db->from('trash_table');
$this->db->where('Description',$_POST['Descp']);
$q = $this->db->get();
if($q->num_rows() > 0 )
//here should be something better
print json_encode($q->result());
}
使用我当前的简单 php 代码,我只是将所有内容都作为 JSONArray 获取。
[
{"ID":1,"Description":"hello",
{"ID":2,"Description":"hellou"}
]
但我想以我自己的方式格式化它,像这样......希望你们帮助。提前谢谢你!
{
"Answer": {
"Success": "Yup"
},
“列表”:[
{"ID":1,
"Description":"hello"},
{"ID":2,
"Description":"hellou"}]
}
【问题讨论】: