我有一个JSON格式对象,我从一个名为teamJSON的变量中的JSON文件中读取,如下所示:
{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"}]}
Run Code Online (Sandbox Code Playgroud)
我想在数组中添加一个新项,例如
{"teamId":"4","status":"pending"}
Run Code Online (Sandbox Code Playgroud)
结束
{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"},{"teamId":"4","status":"pending"}]}
Run Code Online (Sandbox Code Playgroud)
在写回文件之前.添加到新元素的好方法是什么?我接近但所有双引号都被逃脱了.我已经找到了一个很好的答案,但没有一个完全覆盖这个案例.任何帮助表示赞赏.