这是我的rethinkdb数据库中的数据保存。我保存了数据
addtowatchlater
是数组。我使用ember.js作为前端和龙卷风
rethinkdb的后端和数据库。
{
"accesstoken": "ajflasjjfasjfjasfasdfjasjflsajjfas" ,
"addtowatchlater": [
{
"beatdescription": "aa" ,
"beatname": "aa" ,
"categoryname": "DJ" ,
"filename": "asfasdfasdfasdfa" ,
"id": "423423454352342344545423434" ,
"price": "aa" ,
"soldout": "No" ,
"stamp": "1510244267000" ,
"userid": "816fbfe8-ea81-4198-98f0-5fb0db01e25e"
},
{
"beatdescription": "aa" ,
"beatname": "aa" ,
"categoryname": "DJ" ,
"filename": "asfasdfasdfasdfa" ,
"id": "423423454352342344545423434" ,
"price": "aa" ,
"soldout": "No" ,
"stamp": "1510244267000" ,
"userid": "816fbfe8-ea81-4198-98f0-5fb0db01e25e"}] ,
"id": "et4545er5454354354354353" ,
"role": "user" ,
"status": "Active" ,
}
我想从addtowatchlater
数组字段中删除一个json数据。当我
删除我想要这样的例子。
{
"accesstoken": "ajflasjjfasjfjasfasdfjasjflsajjfas" ,
"addtowatchlater": [
{
"beatdescription": "aa" ,
"beatname": "aa" ,
"categoryname": "DJ" ,
"filename": "asfasdfasdfasdfa" ,
"id": "423423454352342344545423434" ,
"price": "aa" ,
"soldout": "No" ,
"stamp": "1510244267000" ,
"userid": "816fbfe8-ea81-4198-98f0-5fb0db01e25e"
}
] ,
"id": "et4545er5454354354354353" ,
"role": "user" ,
"status": "Active" ,
}
答案 0 :(得分:0)
数据是否作为XML文件出现?如果是这样,你可以看到前端的数据,那么你可以在jquery中使用.removedata()轻松实现。
请参考url attatched。如果你能更详细地阐述你的问题,那么可以再次重访,
这里[链接] http://www.jquerybyexample.net/2012/02/remove-item-from-array-using-jquery.html
答案 1 :(得分:0)
首先,将JSON对象转换为Python字典。现在,您可以轻松地使用该数据执行任何操作。
我们假设您的数据如下:
{
"a": [
{
"p": 1,
"q": 2
},
{
"x": 3,
"y": 4
}
],
}
你想要从数组a
中删除一个项目,你可以这样做:
import json
data_dict = json.loads(data) # convert data to python dict
data_dict['a'].pop(0) # remove first item from array `a`
# you can convert data_dict back to json if you want
data = json.dumps(data_dict)