I have a JSON object as shown bellow.I would like to delete the value of the JSON array in the JSON Object using java.I tried using javascript and did it but I am confused with Java.
{
"aaa":"0px",
"bbb":"sadsda",
"ccc":
{
"ddd":
{
"eee":"initial","dsa":"none","asd":"none","caption":"","type":"image","title":"test.txt","align":"center","resolution":null,"captionMargin":"0px auto","href":"ttt/bbb.zzz?cfr=148c273959c9&od=1572cfa","componentbottombordersize":"none","height":null,"border":"0","padding":1,"das":"","src":"ooo","alt":"test.txt","componentbgcolor":"transparent","yandex":null,"target":"_self","hhhh":"none","size":"F","google":"none","microsoft":"100%","name":""
},
"freshdesk":
{
"oooo"
}
},
"width":600,
"zarket":
{
"array":["value1","value2"]
},
"type":"mailchimp",
"height":251
}
I want to delete value1
of array
.How Can I do it using java?
Include this in maven https://mvnrepository.com/artifact/com.google.code.gson/gson
Try this
Gson gson = new GsonBuilder().create();
YourJsonObject yourObj = gson.fromJson(reader, YourJsonObject.class);
if(yourObj.getZarket()!=null && yourObj.getZarket().getArray()!=null){
yourObj.getZarket().getArray().remove("value1");
}
// Assuming you will create a class YourJsonObject with the above attributes of json and the array attribute will be a list. if its an array, remove by searching the value in an array using iterations
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.