0

我正在尝试将一个内爆生成的字符串插入一个数组,然后用于 json 实现

内爆生成的字符串看起来像这样

'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]

我想在这段代码中使用它

$this->_JsonArr[]=array($Generated string);

实现这样的目标

 $this->_JsonArr[]=array('id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]);

相反,我得到了这样的东西

 $this->_JsonArr[]=array(" 'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]");

似乎生成的字符串被视为一个元素作为键和值对。显然我可以从 mysql 获得预期的输出,因此任何人都可以帮助我

4

2 回答 2

1

为什么你需要内爆任何东西?只需传递数组:

$this->_JsonArr[] = your-non-imploded-array-here;

我认为您想要做的事情的完整解决方案是这样的(即您问题中的第三个代码框):

$row = array(
  'id' => $this->_SqlResult[0],
  'UserId' => $this->_SqlResult[1],
  'Msg' => $this->_SqlResult[2],
  'MsgStamp' => $this->_SqlResult[3]
);
$this->_JsonArr[] = $row;
于 2011-04-22T11:57:15.153 回答
0

$this->_JsonArr[]=array($Generated string);

看起来您想使用数组键和值,但是正如我看到的那样,您将纯字符串放入数组中,并期望数组以以下格式解析纯字符串:键 => 值。

您可以尝试创建如下数组:

$this->_JsonArr[ $Generated_key ] = array( $Generated_value );

(如果我理解错了你的问题,请纠正我)。

于 2011-04-22T12:30:20.720 回答