我有这个json文件:
{
"module": {
"data": {
"orderInfo_203759231000": {
"fields": {
"createdAt": "Dipesan pada\\r\\n 17 Mei 2018",
"tradeOrderId": 203759231000
}
},
"orderInfo_203759231000": {
"fields": {
"createdAt": "Dipesan pada\\r\\n 22 Mei 2018",
"tradeOrderId": 203759231000
}
},
"orderInfo_203759231000": {
"fields": {
"createdAt": "Dipesan pada\\r\\n 22 Mei 2018",
"tradeOrderId": 203759231000
}
},
"orderInfo_203759231000": {
"fields": {
"createdAt": "Dipesan pada\\r\\n 22 Mei 2018",
"tradeOrderId": 203759231000
}
},
"orderInfo_203759231000": {
"fields": {
"createdAt": "Dipesan pada\\r\\n 22 Mei 2018",
"tradeOrderId": 203759231000
}
}
}
}
}
我希望删除Dipesan pada\\r\\n
这是我尝试过的内容:
sed 's/Dipesan pada \\\\r\\\\n//g' file.json
但它不起作用,我希望最终结果只是这样的日期:
"createdAt": "17 Mei 2018",
"createdAt": "22 Mei 2018",
"createdAt": "22 Mei 2018",
etc...
我该如何解决?
答案 0 :(得分:2)
你的反斜杠很好,恭喜!问题在于放置一个讨厌的空间:
<?php
$imgsql=mysqli_query($link,"select eve_pic,eve_pic2,eve_pic3,eve_pic4 from event_tbl");
if( mysqli_num_rows($imgsql)>0 ){
$imgrow=mysqli_fetch_array($imgsql);
}
if(!empty($imgrow['eve_pic'])){
?>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class=sz_portfolio_003_trig_wrap>
<div class=sz_portfolio_003_trig_img>
<div class=sz_portfolio_003_trig_btn>
<a href=#sz_portfolio_003_4_col data-backdrop=true data-slide-to=0 data-toggle=modal>
<img src="admin/uploads/eventpics/<?php echo $imgrow['eve_pic'];?>" alt="sz_portfolio_003_01" width="200px" height="200px" class="imagen"/></a>
</div>
</div>
</div>
</div>
<?php
}
?>
答案 1 :(得分:1)
将jq
与update operator和sub过滤器一起使用,您可以按照以下方式执行此操作。斜杠需要转义两次以使其正常工作
jq '(.module.data[].fields.createdAt)|=(sub("Dipesan pada\\\\r\\\\n ";""))' input.json
在jq-play上测试过。这是在您的JSON输入上测试的,其中修改了密钥以避免重复。