I have a JSON format object I read from a JSON file that I have in a variable called teamJSON, that looks like this:
(我有一个从JSON文件读取的JSON格式对象,该对象包含在一个名为teamJSON的变量中,如下所示:)
{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"}]}
I want to add a new item to the array, such as
(我想向数组添加一个新项,例如)
{"teamId":"4","status":"pending"}
to end up with
(最终)
{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"},{"teamId":"4","status":"pending"}]}
before writing back to the file.
(在写回文件之前。)
What is a good way to add to the new element?(什么是添加到新元素的好方法?)
I got close but all the double quotes were escaped.(我接近了,但是所有双引号都被转义了。)
I have looked for a good answer on SO but none quite cover this case.(我一直在寻找一个很好的答案,但是没有一个案例能解决这个问题。)
Any help is appreciated.(任何帮助表示赞赏。)
ask by Charles Wyke-Smith translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…