【发布时间】:2014-06-10 15:47:31
【问题描述】:
if($stmt->execute()){
$user = $stmt->get_result();
while ($obj = $user->fetch_object()) {
$result[] = $obj;
}
}
$result1encoded = json_encode($result);
echo $result1encoded;
// [{"uId":"1","firstName":"John"}]
我这样使用内爆:
echo $result1encoded = implode(' ',$result1);
// expecting '[{"uId":"1","firstName":"John"}]'
但它说
Object of class stdClass could not be converted to string
【问题讨论】:
-
$result1 是对象数组。因此,由于数组元素在这里是对象,它们不能转换为字符串。 implode 需要字符串元素。
-
当您已经使用
json_encode获得结果时,为什么还要使用implode -
你能发一下
print_r($result);吗? -
@ShankarDamodaran 数组 ([0] => stdClass 对象 ([uId] => 1 [firstName] => John ))
-
@user3522462,您检查以下答案了吗?
标签: php json type-conversion