0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

.Net 6: C# で JSON の Delete

Last updated at Posted at 2022-08-07

.Net のバージョン

$ dotnet --version
6.0.302

プロジェクトの作成

mkdir Delete01
cd Delete01
dotnet new console

フォルダー構造

$ tree -L 1
.
├── Delete01.csproj
├── Program.cs
├── file_io.cs
└── obj
Program.cs
// --------------------------------------------------------------------
//	Program.cs
//
//						Aug/07/2022
// --------------------------------------------------------------------
using System;  
using System.IO;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

// --------------------------------------------------------------------
namespace Update01
{
	class Program
	{
	static void Main(string[] args)
	{
		Console.Error.WriteLine("*** 開始 ***");

		string file_json = args[0];

		string	key_in = args[1];
		Console.WriteLine (key_in);

		string str_json = file_io.file_to_str_proc (file_json);

		Dictionary <string,Object> dict_aa = JsonSerializer.Deserialize
				  <Dictionary <string,Object>> (str_json)!;

		if (dict_aa.ContainsKey (key_in))
		{
		dict_aa.Remove (key_in);
		string str_json_out = JsonSerializer.Serialize(dict_aa);

		file_io.file_write_proc (file_json,str_json_out);
		}

	Console.Error.WriteLine("*** 終了 ***");
	}

// --------------------------------------------------------------------
	}
}

// --------------------------------------------------------------------

file_io.cs はこちら
.Net Core で JSON の Update

コンパイル

dotnet build

実行

bin/Debug/net6.0/Delete01 /var/tmp/json/tochigi.json t0925
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?