无法解析JSON文件,Progam.cs asp.net核心中的错误 [英] Could not parse the JSON file ,Error in Progam.cs asp.net core

查看:246
本文介绍了无法解析JSON文件,Progam.cs asp.net核心中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

program.cs文件和ASP.NetCORE 2.0的版本存在一些问题

I have some issues with the program.cs file, with the version of ASP.NetCORE 2.0

这是我的代码

     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 run the project, following error occurs.

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

如何解决?

推荐答案

我在另一个线程中遇到了与此类似的问题,并将我的解决方案发布到了那里:

I had a a similar problem as this in another thread and posted my solution over there: Application Startup Failure with Json read Error. Posting it here as well in case it disappears.

我遇到了同样的问题.就我而言,我将开始实施应用程序的机密,但半途而废.我的secrets.json文件被保留链接,但使用无效的JSON.

I came across the same problem. In my case, I'd started implementing app secrets but left it halfway through. My secrets.json file was left linked but with invalid JSON.

检查您的.csproj以查看是否在<PropertyGroup>下设置了<UserSecretId>属性.如果已设置,除了appsettings.json文件之外,BuildWebHost()还将浏览'%APPDATA%\Microsoft\UserSecrets\{secretId}'中的secrets.json文件.任何一个文件中的错误都会导致该方法失败,但不会告诉您该文件是哪个文件.

Check your .csproj to see if a <UserSecretId> property is set under <PropertyGroup>. If it's set, BuildWebHost() will look through your secrets.json file in '%APPDATA%\Microsoft\UserSecrets\{secretId}', in addition to your appsettings.json file. An error in either file will cause the method to fail, but it won't tell you which file it is.

我的解决方案是删除<UserSecretId>属性或

The solutions in my case were either to remove the <UserSecretId> property or

这篇关于无法解析JSON文件,Progam.cs asp.net核心中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆