Could not parse the JSON file ,Error in Progam.cs

2020-06-16 02:33发布

I have some problem with program.cs new version in ASP.CORE 2.0

Here my code

     public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseKestrel()
            .UseStartup<Startup>()
            .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build())
            .Build();

}

When i start project i has an error

System.FormatException: 'Could not parse the JSON file. Error on line number '0': ''.'

How to resolve it?

标签: c# asp.net json
8条回答
叼着烟拽天下
2楼-- · 2020-06-16 03:16

I had this problem and the reason is that for some reason Visual Studio saves files with some invisible metadata that goes before the text therefore JSON reader cannot parse it.

You need to File -> Save As -> (Choose UTF-8 Without BOM).

查看更多
Explosion°爆炸
3楼-- · 2020-06-16 03:19

in m case I put extra { right before (above) "ConnectionStrings" : in appsettings.json

I copied this from another file and assumed that "ConnectionStrings" : must inside a curly braces {}

before

...
},
{  //<-- this one the culprit
    "ConnectionStrings": {
      "Dapper": "Server=.;Database=Dapper;Trusted_Connection=True;"
    },

after

...
},
    "ConnectionStrings": {
      "Dapper": "Server=.;Database=Dapper;Trusted_Connection=True;"
    },
查看更多
登录 后发表回答