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 "何かキーを押してください"
|
|
【PowerShell + C#の最新記事】
- PowerShell を使用して、C# のコンソールアプリ用のソースコードから exe を作成する( WebClient で wget.exe ) / ビルドせずに PowerShell で実行
- PowerShell で VisualStudio で作成した Form アプリケーションをビルドする( DataGridView に select 文の結果を表示する / MySQL )
- PowerShell で VisualStudio で作成した Form アプリケーションをビルドする( Form アプリケーションを テキストエディタのみで作成するテンプレート )
- TKMP + imap + C# + PowerShell : メールボックス(階層)の一覧表示
- nuget.exe + SMO + PowerShell + C# : テーブルの CREATE TABLE 文 を取得
- PowerShell( 実質C# )を使用して、ファイルの分割を行う
- PowerShell( 実質C# )を使用して、MessageBox の応答でバッチファイルの処理を変化させる
- PowerShell で C# のソースコード(get_rec_mysql.cs) を使用して System.Data.Odbc で MySQL のデータを一覧表示( csv )






