Skip to content

Instantly share code, notes, and snippets.

@daisukenishino2
Created September 6, 2018 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daisukenishino2/21e7f14acfa281c00c855b09b95c0307 to your computer and use it in GitHub Desktop.
Save daisukenishino2/21e7f14acfa281c00c855b09b95c0307 to your computer and use it in GitHub Desktop.
// jsonファイルを読み込んでjsonを返す。
// コンストラクタの引数は、ファイルからロードした文字列
return new HttpResponseMessage()
{
Content = new JsonContent(
ResourceLoader.LoadAsString(
OAuth2AndOIDCParams.JwkSetFilePath,
Encoding.GetEncoding(CustomEncode.UTF_8)))
};
// JsonSerializerSettingsを指定して、可読性の高いJSONを返す。
// コンストラクタの引数は、文字列とJsonSerializerSettings
return new HttpResponseMessage()
{
Content = new JsonContent(OpenIDConfig,
new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver()
})
};
@daisukenishino2
Copy link
Author

daisukenishino2 commented Sep 6, 2018

利用方法

ASP.NET MVC5のWebAPIから文字列で組み立てたJSONを返したい場合に利用できると思います。

サンプル

インストール

v 2.3.0 以降で利用可能。

Install-Package Touryo.Infrastructure.Framework

もしくは、

Install-Package Touryo.Infrastructure.Framework -Version 2.3.0

名前空間

Touryo.Infrastructure.Framework.Presentation

必要に応じて、using, Importsする。

using Touryo.Infrastructure.Framework.Presentation;
Imports Touryo.Infrastructure.Framework.Presentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment