I have a JSON archive and I want find and delete one object. How to find and delete object in a JSON archive?
Example:
{
"themes":[
{"name":"pepito",
"thumbnail":"http://nakome.16mb.com/samples/html/admin/",
"description":"Simple"},
// Delete this in php ---------
{"name":"juanito",
"thumbnail":"http://nakome.16mb.com/samples/html/admin/",
"description":"Simple" }
// ----------------------------
]
}
You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.
toJSON() calls the object's toISOString() method, which returns a string representing the Date object's value. This method is generally intended to, by default, usefully serialize Date objects during JSON serialization, which can then be deserialized using the Date() constructor or Date. parse() as the reviver of JSON.
JsonObject::remove() removes a key-value pair from the object pointed by the JsonObject . If the JsonObject is null, this function does nothing.
Without having to write your own parser (and given it's php) use json_decode
and turn it in to an object you want to work with, use unset
then re-json_encode
the result.
That would be the easiest way without having to perform string parsing/searches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With