"application/json" constant in .NET framework

I've just declared a constant for the "application/json" content type in one of my classes.

public const string JsonContentType = "application/json";

I'm not sure it is a good practice.

Does .NET framework have a predefined const for "application/json"?

Answers


While there are some MIME constants defined in MediaTypeNames (see here), there no constant for "application/json".

Putting additional content types in a shared const is probably best practice, better than defining them in string literals a million times throughout your code at least.

Plus it gives you the flexibility of using new/custom MIME types, which a specific .NET version might not have.


In order to add an up-to-date answer: since dotnet core 2.1 MediaTypeNames.Application.Json has been defined.

See https://github.com/dotnet/corefx/pull/26701 for the changeset.


Need Your Help

How to Display result of subquery rows as one column in MySQL?

mysql pivot

I have three tables Category, Movies and RelCatMov

Android - Remove CacheColorHint for ListView

android android-layout

I am developing Android Application having the listview in an activity. I implemented the listview in an activity. By default, while scrolling the list, the background of the entire list changes to...