Removing from an array¶
You have quite a few options to remove objects from JsonArrays:
We have this json:¶
[
"avocados",
"red beans",
"hazelnuts",
"flour",
"onion powder"
]
To remove an element by index:¶
Json json;
json.Parse(aboveJsonCode); // we have an already filled json
// Remove the element at index 3.
// Exception if out of range
json.AsArray.RemoveAt(3);
To remove elements by value:¶
Json json;
json.Parse(aboveJsonCode); // we have an already filled json
// Remove all string-values with value "hazelnuts"
json.AsArray.RemoveSimilar(JsonData("hazelnuts"));
To remove all non-string elements:¶
Json json;
json.Parse(aboveJsonCode); // we have an already filled json
// Remove all non-string-values
json.AsArray.RemoveAllExceptType(JSON_DATA_TYPE::STRING);
To remove all string elements:¶
Json json;
json.Parse(aboveJsonCode); // we have an already filled json
// Remove all string-values
json.AsArray.RemoveAllOfType(JSON_DATA_TYPE::STRING);