Json读取错误导致应用程序启动失败 [英] Application Startup Failure with Json read Error

查看:86
本文介绍了Json读取错误导致应用程序启动失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的解决方法,但是事实证明它很难捉摸.我不断收到错误消息

This was suppose to an easy fix, it however proving very elusive. I keep getting the error

An error occurred while starting the application.JsonReaderException: Invalid property identifier character: {. Path '', line 2, position 2.Newtonsoft.Json.JsonTextReader.ParseProperty()FormatException: Could not parse the JSON file. Error on line number '2': '{{'.Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(bool reload) JsonReaderException: Invalid property identifier character: {. Path '', line 2, position 2.

我正在开发.net核心Web应用程序.我在同一解决方案中有两个Web应用程序.我将appsettins文件从正在运行的Web应用程序移至出现问题的应用程序,情况仍然相同.无法找出我所缺少的东西

I working on an .net core web app. I have two web apps in the same solution. I moved the appsettins file from the working Web app to the one giveing the problem and the situation is still the same. Cant figure out what I am missing

下面是我的appsettings.json文件

below is my appsettings.json file

{
  "Data": {
    "UserDbConn": {
      "connString": "Server=DbServer;Database=BookDB;    Trusted_Connection=True;MultipleActiveResultSets=true"
    }
  },
    "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }

推荐答案

我遇到了同样的问题.就我而言,我将开始实施应用程序的机密,但半途而废.我的 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> 属性.如果已设置,则 BuildWebHost()将浏览'%APPDATA%\ Microsoft \ UserSecrets \ {secretId}'中的 secrets.json 文件,以及您的 appsettings.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读取错误导致应用程序启动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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