【发布时间】:2022-01-04 22:39:46
【问题描述】:
{
"page": {
"size": 2,
"number": 2
},
"places": [
{
"eventName": "XYZ",
"createdByUser": "xyz@xyz.com",
"modifiedDateTime": "2021-03-31T09:59:48.616Z",
"modifiedByUser": "xyz@xyz.com"
}
]}
我正在尝试使用新字符串更新“eventName”字段。我尝试使用以下代码,它更新了字段,但只返回了 json 数组中的四个字段。
public String modifyJson() throws Exception{
String jsonString = PiplineJson.payload(PiplineJson.filePath());
System.out.println(jsonString);
JSONObject jobject = new JSONObject(jsonString);
String uu = jobject.getJSONArray("places")
.getJSONObject(0)
.put("eventName", randomString())
.toString();
System.out.println(uu);
return uu;
}
这就是上面代码的作用。
{
"eventName": "ABCD",
"createdByUser": "xyz@xyz.com",
"modifiedDateTime": "2021-03-31T09:59:48.616Z",
"modifiedByUser": "xyz@xyz.com"
}
一旦更新了 eventName 文件,我将尝试获取完整的 json。
{
"page": {
"size": 2,
"number": 2
},
"places": [
{
"eventName": "ABCD",
"createdByUser": "xyz@xyz.com",
"modifiedDateTime": "2021-03-31T09:59:48.616Z",
"modifiedByUser": "xyz@xyz.com"
}
]}
【问题讨论】: