简体   繁体   中英

How do i delete an json element from an array?

So I'm using a REST sandbox API to delete a "Call" from a state array, and the array contains all JSON not sure what to use to remove it.

Do note: This is connecting through HTTP from a Lua Script ran Request.

Website: getsandbox.com

Here's the code:

 //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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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