ps.bat ( PowerShell をそのまま使えない場合は以下のバッチファイルを作成して使用します )@powershell -NoProfile -ExecutionPolicy Unrestricted "./%1.ps1"nuget.exe - recommended latest のダウンロードページ nuget.exe CLI を使用してパッケージを管理する( Microsoft のドキュメント )nuget.exe を最新にするには nuget update -Self ここで使用するパッケージの最新バージョンの確認は こちらから 行って以下のコマンドライン nuget install Newtonsoft.Json -Version バージョンjson_sample_01.cs
using System; using System.IO; using System.Text; using System.Net; using System.Web; using System.Windows.Forms; using Newtonsoft.Json; public class Program { public static void Main() { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string url = "https://lightbox.sakura.ne.jp/demo/json/syain_json.php"; string json = ""; using( WebClient wc = new WebClient() ) { wc.Encoding = Encoding.UTF8; json = wc.DownloadString( url ); } Syain[] syain = JsonConvert.DeserializeObject<Syain[]>(json); foreach (Syain data in syain) { Console.WriteLine( data.社員コード ); Console.WriteLine( data.氏名 ); Console.WriteLine( data.フリガナ ); } MessageBox.Show("処理が終了しました"); } private class Syain { public string 社員コード { get; set; } public string 氏名 { get; set; } public string フリガナ { get; set; } } }
build.ps1 Newtonsoft.Json.dll は、ソースコードと同じ場所に置きます
Add-Type -path "json_sample_01.cs" ` -ReferencedAssemblies "Newtonsoft.Json.dll", System.Web, System.Windows.Forms ` -OutputAssembly json_sample_01.exe ` -OutputType ConsoleApplication Read-Host "何かキーを押してください"
run.ps1 Newtonsoft.Json.dll は、ソースコードと同じ場所に置きます
Add-Type -path "Newtonsoft.Json.dll" Add-Type -path "json_sample_01.cs" ` -ReferencedAssemblies "Newtonsoft.Json.dll", System.Web, System.Windows.Forms [Program]::Main() Read-Host "何かキーを押してください"