我从服务器收到了以下json字符串响应。
{
"entities":[
{
"Fields":[
{
"Name":"detection-version",
"values":[
{
}
]
},
{
"Name":"subject",
"values":[
]
},
{
"Name":"description",
"values":[
{
}
]
},
{
"Name":"target-rcyc",
"values":[
{
}
]
},
{
"Name":"project",
"values":[
{
}
]
},
{
"Name":"changeset",
"values":[
{
}
]
},
{
"Name":"has-linkage",
"values":[
{
"value":"N"
}
]
},
{
"Name":"last-modified",
"values":[
{
"value":"2016-05-31 18:38:54"
}
]
},
{
"Name":"has-others-linkage",
"values":[
{
"value":"N"
}
]
},
{
"Name":"attachment",
"values":[
{
}
]
},
{
"Name":"cycle-id",
"values":[
]
},
{
"Name":"request-type",
"values":[
{
}
]
},
{
"Name":"build-detected",
"values":[
{
}
]
},
{
"Name":"creation-time",
"values":[
{
"value":"2016-05-17"
}
]
},
{
"Name":"actual-fix-time",
"values":[
]
},
{
"Name":"id",
"values":[
{
"value":"4"
}
]
},
{
"Name":"run-reference",
"values":[
]
},
{
"Name":"request-note",
"values":[
{
}
]
},
{
"Name":"request-server",
"values":[
{
}
]
},
{
"Name":"severity",
"values":[
{
"value":"1-Low"
}
]
},
{
"Name":"to-mail",
"values":[
{
}
]
},
{
"Name":"owner",
"values":[
{
}
]
},
{
"Name":"detected-by",
"values":[
{
"value":"demouser02"
}
]
},
{
"Name":"build-closed",
"values":[
{
}
]
},
{
"Name":"step-reference",
"values":[
]
},
{
"Name":"estimated-fix-time",
"values":[
]
},
{
"Name":"reproducible",
"values":[
{
}
]
},
{
"Name":"ver-stamp",
"values":[
{
"value":"1"
}
]
},
{
"Name":"request-id",
"values":[
]
},
{
"Name":"priority",
"values":[
{
}
]
},
{
"Name":"cycle-reference",
"values":[
{
}
]
},
{
"Name":"environment",
"values":[
{
}
]
},
{
"Name":"target-rel",
"values":[
{
}
]
},
{
"Name":"test-reference",
"values":[
]
},
{
"Name":"planned-closing-ver",
"values":[
{
}
]
},
{
"Name":"extended-reference",
"values":[
{
}
]
},
{
"Name":"dev-comments",
"values":[
{
}
]
},
{
"Name":"detected-in-rcyc",
"values":[
{
}
]
},
{
"Name":"closing-version",
"values":[
{
}
]
},
{
"Name":"name",
"values":[
{
"value":"test"
}
]
},
{
"Name":"has-change",
"values":[
{
}
]
},
{
"Name":"user-01",
"values":[
{
}
]
},
{
"Name":"has-changeset-link",
"values":[
{
"value":"N"
}
]
},
{
"Name":"detected-in-rel",
"values":[
{
}
]
},
{
"Name":"status",
"values":[
{
}
]
},
{
"Name":"closing-date",
"values":[
]
}
],
"Type":"defect",
"children-count":0
},
{
"Fields":[
{
"Name":"detection-version",
"values":[
{
}
]
},
{
"Name":"subject",
"values":[
]
},
{
"Name":"description",
"values":[
{
}
]
},
{
"Name":"target-rcyc",
"values":[
{
}
]
},
{
"Name":"project",
"values":[
{
}
]
},
{
"Name":"changeset",
"values":[
{
}
]
},
{
"Name":"has-linkage",
"values":[
{
"value":"N"
}
]
},
{
"Name":"last-modified",
"values":[
{
"value":"2016-05-31 18:38:58"
}
]
},
{
"Name":"has-others-linkage",
"values":[
{
"value":"N"
}
]
},
{
"Name":"attachment",
"values":[
{
}
]
},
{
"Name":"cycle-id",
"values":[
]
},
{
"Name":"request-type",
"values":[
{
}
]
},
{
"Name":"build-detected",
"values":[
{
}
]
},
{
"Name":"creation-time",
"values":[
{
"value":"2016-05-17"
}
]
},
{
"Name":"actual-fix-time",
"values":[
]
},
{
"Name":"id",
"values":[
{
"value":"5"
}
]
},
{
"Name":"run-reference",
"values":[
]
},
{
"Name":"request-note",
"values":[
{
}
]
},
{
"Name":"request-server",
"values":[
{
}
]
},
{
"Name":"severity",
"values":[
{
"value":"1-Low"
}
]
},
{
"Name":"to-mail",
"values":[
{
}
]
},
{
"Name":"owner",
"values":[
{
}
]
},
{
"Name":"detected-by",
"values":[
{
"value":"demouser02"
}
]
},
{
"Name":"build-closed",
"values":[
{
}
]
},
{
"Name":"step-reference",
"values":[
]
},
{
"Name":"estimated-fix-time",
"values":[
]
},
{
"Name":"reproducible",
"values":[
{
}
]
},
{
"Name":"ver-stamp",
"values":[
{
"value":"1"
}
]
},
{
"Name":"request-id",
"values":[
]
},
{
"Name":"priority",
"values":[
{
}
]
},
{
"Name":"cycle-reference",
"values":[
{
}
]
},
{
"Name":"environment",
"values":[
{
}
]
},
{
"Name":"target-rel",
"values":[
{
}
]
},
{
"Name":"test-reference",
"values":[
]
},
{
"Name":"planned-closing-ver",
"values":[
{
}
]
},
{
"Name":"extended-reference",
"values":[
{
}
]
},
{
"Name":"dev-comments",
"values":[
{
}
]
},
{
"Name":"detected-in-rcyc",
"values":[
{
}
]
},
{
"Name":"closing-version",
"values":[
{
}
]
},
{
"Name":"name",
"values":[
{
"value":"test"
}
]
},
{
"Name":"has-change",
"values":[
{
}
]
},
{
"Name":"user-01",
"values":[
{
}
]
},
{
"Name":"has-changeset-link",
"values":[
{
"value":"N"
}
]
},
{
"Name":"detected-in-rel",
"values":[
{
}
]
},
{
"Name":"status",
"values":[
{
}
]
},
{
"Name":"closing-date",
"values":[
]
}
],
"Type":"defect",
"children-count":0
}
],
"TotalResults":920
}
我需要为此字符串中的所有缺陷更新以下值
{
"Name":"detected-by",
"values":[
{
"value":"demouser02"
}
]
}
我需要更新检测到“报告者”和demouser02到“Adwait”
请帮忙。
答案 0 :(得分:0)
如果我理解你的意思,你可以做这样的事情:
public class EntiteFile extends Serializable{
private List<Entite<Filed>> entites;
....
}
public class Entite<Filed> extends Serializable {
private List<Filed> fileds;
}
public clas Value extends Serializable {
private String value;
....
}
public class Filed extends Serializable {
private String name;
private List<Value> values ;
.....
}
要阅读您的文件,您可以使用:
EntiteFile entities = mapper.readValue(getJsonFile(nameFile), EntiteFile.class);
for(Entite entite : entities.getEntites ){
for(Field field : Fields ){
if("detected-by".equals(field.getName())){
field.setName("Reported by");
for(Value value : field.getValues){
value.setValue("Adwait");
}
}
}
}
... ...
答案 1 :(得分:0)
JSONSimple。尽可能简单。试试吧! https://www.mkyong.com/java/json-simple-example-read-and-write-json/