繁体   English   中英

如何从数组中删除json元素?

[英]How do i delete an json element from an array?

因此,我正在使用REST沙盒API从状态数组中删除“调用”,并且该数组包含所有JSON,不确定如何删除它。

请注意:这是通过Lua脚本运行请求通过HTTP连接的。

网站:getsandbox.com

这是代码:

 //Store Calls state.calls = state.calls || [] var calls = state.calls; /* | | Create Call V */ Sandbox.define('/new/call/','POST', function(req, res){ var gameid = req.get("Roblox-Id"); var person = req.body.split(" ")[0]; var reason = req.body.split(" ")[1]; var comp = { gameid: gameid, player: person, callreason: reason }; calls.push(comp); // Set the type of response, sets the content type. res.type('text/plain'); // Set the status code of the response. res.status(200); // Send the response body. res.send('Request Accepted'); }); /* | | Get Calls V */ Sandbox.define('/get/calls/','GET', function(req, res){ // Check the request, make sure it is a compatible type // Set the type of response, sets the content type. res.type('application/json'); // Set the status code of the response. res.status(200); // Send the response body. res.send(calls); }) /* | | Delete v */ Sandbox.define('/data/delete/{gameid}/','GET', function(req, res){ for(i=0;i<calls.length;i++){ calls[i].pop(); } // Set the type of response, sets the content type. res.type('text/plain'); // Set the status code of the response. res.status(200); // Send the response body. res.send('Successful'); }) 

查找callindex并使用以下命令:

calls.splice(index, 1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM