我已经检查过了,找不到这个问题的答案。我有一个查询,它返回给定 ID 数组的表"链接标签修订"中的"内容"值。查询是循环的,然后数据作为 json 字符串输出。
"内容"已序列化,如何反序列化并显示在 JSON 输出中?
这是我的代码:
public function testAction()
{
//Get latest revision from database and loop through $id's
$id = array('308', '307', '306');
//setup array and loop
$result = array();
foreach($id as $lId) {
//Connect to database
$db = Zend_Db_Table::getDefaultAdapter();
//Perform Query
$select = $db->select('')
->from(array('lr'=>'LinktagRevisions'),
array('content'))
->where('linktagId = ?', $lId)
->order('updated DESC')
->limit(1);
$stmt = $select->query();
$result[$lId] = $stmt->fetch();
}
$this->_helper->json($result,true);
}
尝试不同事物时我得到的标准错误是:
警告:unserialize() 期望参数 1 为字符串
$phpNative = Zend_Json::decode($encodedValue);
$json = Zend_Json::encode($phpNative);
http://framework.zend.com/manual/1.12/en/zend.json.basics.html