IDataUnpacker.RemoveKey(string key) Method
.NET Standard 2.x
Removes the element from the IDataUnpacker
object according to the specified key.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
bool RemoveKey(string key);
Parameters
key
System.String
The key of the element to remove.
Returns
System.Boolean
Returns true
if the element is successfully removed; returns false
if the key was not found.
Examples
The following code example deletes the element with the specified key from the IDataUnpacker
object.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IDataUnpackerExamples
{
public class RemoveKeyExample
{
private readonly SchoolContext _context;
public RemoveKeyExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
// Normally, you should receive a JSON string in the Response Body.
// It creates a DataPacker object here just for this example.
var packer = new DataPacker();
packer.AddValue("Key1", "Value1");
var json = packer.GetTextString(DataFormat.Json);
// Creates a DataUnpacker object using the JSON string.
// In a controller class, you can also use a IDataUnpacker type as a
// parameter to receive a JSON Package format JSON string from the
// Request Body.
var dataUnPacker = new DataUnpacker(json, DataFormat.Json);
Console.WriteLine("ContainsKey (Before Removed): {0}",
dataUnPacker.ContainsKey("Key1"));
// Removes "Key1" from DataUnpacker
dataUnPacker.RemoveKey("Key1");
Console.WriteLine("ContainsKey (After Removed): {0}",
dataUnPacker.ContainsKey("Key1"));
/* This code example produces the following output:
ContainsKey (Before Removed): True
ContainsKey (After Removed): False
*/
}
}
}
Applies to
.NET Standard
2.x