python删除json数组数据_如何使用python删除json对象?

这篇博客介绍了如何使用Python从JSON文件中删除特定对象。作者提供了一个示例JSON数据,包含两个对象,目标是删除ename为'mark'的对象。博主尝试将对象转换为字典进行删除但未成功。解决方案是通过加载JSON文件,遍历对象列表,找到目标对象并使用pop()方法删除。代码示例中展示了如何保存更新后的JSON文件。
摘要由CSDN通过智能技术生成

I am using python to delete and update a JSON file generated from the data provided by user, so that only few items should be stored in the database. I want to delete a particular object from the JSON file.

My JSON file is:

[

{

"ename": "mark",

"url": "Lennon.com"

},

{

"ename": "egg",

"url": "Lennon.com"

}

]

I want to delete the JSON object with ename mark.

As I am new to python I tried to delete it by converting objects into dict but it is not working. Is there any other way to do it?

i tried this one:

index=0

while index < len(data):

next=index+1

if(data[index]['ename']==data[next]['ename']):

print "match found at&#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值