我收到无效的属性标识符字符:‘.路径 '',第 1 行,位置 1,同时将 json 字符串解析为对象。 我的 Json 字符串看起来像这样
{‘name’ : ‘Account’ , ‘placeholder’ : ‘Enter Accountant Name’ , ‘label’ : ‘Account Name’ , ‘type’ : ‘string’ , ‘mode’: ‘multiline’}
类看起来像这样
public class TemplateModel
{
public string name { get; set; }
public string type { get; set; }
public string placeholder { get; set; }
public string label { get; set; }
public string mode { get; set; } = "single";
}
我在这一行中遇到错误。
var list = JsonConvert.DeserializeObject(d);
我已经检查了 Newtonsoft.Json 文档并在复制示例并替换为我的键和静态值时找到了一个示例。它工作正常。示例中的字符串如下所示。
var c= @"{'name': 'james@example.com', 'type': 'string', 'label': 'Name', 'placeholder':'Enter Name', 'mode': 'multiline'}";
当我在 json 验证器中在线验证我的 json 字符串时,它验证正确,除了它将我的 ' ' 替换为 ""但我使用了 ' ',因为它在 Newtonsoft.Json 示例中是这样使用的。
我正在从 word 文件中读取我的 json 字符串模板。我的 json 在文本 visulazar 中看起来像这样。
请帮忙。
我在 fiddle 中创建了这个问题,请检查 https://dotnetfiddle.net/BTma0B
最佳答案
看起来您使用的是智能引号而不是普通引号。
我在服务器端用普通引号尝试了以下内容
{
"name":"Account",
"placeholder":"Enter Accountant Name",
"label":"Account Name",
"type":"string",
"mode":"multiline"
}
这很好用。
您能否通过更改引号来验证这是否适合您?
关于c# - 无效的属性标识符字符 : ‘. Path ' ', 第 1 行,将 json 字符串解析为对象时的位置 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63603097/