Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Simple string returned by controller action is not a valid JSON! #4945

@ryanelian

Description

@ryanelian
[HttpGet]
public string Get()
{
    return "Hello World!";
}

ASP.NET MVC Core 1.0.0 does this:

200 OK

Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Server: Kestrel
X-SourceFiles: =?UTF-8?B?RDpcVlNcQWNjZWxpc3QuQUlTXEFjY2VsaXN0LkFJUy5XZWJBcHBcYXBpXHZhbHVlcw==?=
X-Powered-By: ASP.NET
Date: Fri, 01 Jul 2016 10:18:31 GMT

Hello World!

Meanwhile in ASP.NET Web API 5.2.3 does this:

200 OK

Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RDpcVlNcQWNjZWxpc3QuTURNXEFjY2VsaXN0Lk1ETS5TZXJ2ZXJcYXBpXHRlc3Q=?=
X-Powered-By: ASP.NET
Date: Fri, 01 Jul 2016 10:22:10 GMT
Content-Length: 13

"Hello World"

ASP.NET MVC 5.2.3, when returningJson("Hello World", JsonRequestBehavior.AllowGet), does this:

200 OK

Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/10.0
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RDpcVlNcQWNjZWxpc3QuTURNXEFjY2VsaXN0Lk1ETS5TZXJ2ZXJcaGVsbG8=?=
X-Powered-By: ASP.NET
Date: Fri, 01 Jul 2016 10:23:57 GMT
Content-Length: 13

"Hello World"

This is an unexpected behavior for me. Is this a bug or feature? I believe "Hello World!" is a valid JSON response, not Hello World!. Javascript JSON.parse() function can parse the former but not the latter.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions