[英]PHP > How to skip an element while using json_encode
I need to send data to the client side in JSON format. 我需要以JSON格式将数据发送到客户端。
So far, it worked just fine with json_encode as follows: 到目前为止,它可以与json_encode一起正常工作,如下所示:
$sql = "SELECT `card`.`CardID`,`card`.`Text`,... WHERE (`card`.`CardID`= :ItemId)";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':ItemId', $itemid);
$stmt->execute();
while ($row = $stmt->fetchObject()) {
$posts[]=$row;
}
...
...
$res["rows"] = $posts;
$res["maptel"] = $maptelindicator;
echo json_encode($res,JSON_UNESCAPED_UNICODE);
But now I have a problem. 但是现在我有一个问题。 I have a new field (Videofiles) in the DB that is already JSON formatted- stored as the ouput of a SDK function.
我在数据库中有一个新字段(视频文件),该字段已经是JSON格式的-存储为SDK函数的输出。 If I encode this JSON encoded field once more, I get data which is unreadable on the client side..
如果我再次对该JSON编码字段进行编码,那么我将获得客户端无法读取的数据。
How can I json_encode all the other data, but skip this specific field, Videofiles? 如何对所有其他数据进行json_encode,但跳过此特定字段Videofiles?
Here is the output of a sample data structure using print_r: 这是使用print_r的示例数据结构的输出:
Array
(
[rows] => Array
(
[0] => stdClass Object
(
[Name] => Company13
[CID] => 26
[CardID] => 26-000002
[Text] => Kleopatra Deluxe Hotel reservations
[ImageLink] =>
[VideoFiles] => [{"quality":"mobile","type":"video/mp4","width":480,"height":270....}]
[ClickDate] => 2015-11-03
)
)
[maptel] => 0
)
Thanks... 谢谢...
您可以使用json_decode
解码已经编码的字段,然后将结果添加到$res
数组中。
Best way to do it delete this section in SQL!
最佳方法是在SQL中删除此部分!
But if you want to delete in php it will have a cost for you and you can use unset for this situation; 但是,如果要在php中删除, 则需要付出一定的代价,在这种情况下可以使用unset;
foreach ($posts as $post){
unset($posts['VideoFiles']);
}
$res["rows"] = $posts;
$res["maptel"] = $maptelindicator;
echo json_encode($res,JSON_UNESCAPED_UNICODE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.