Reputation: 151
I am getting Invalid property identifier character: ‘. Path '', line 1, position 1 while parsing json string to object. My Json string look like this
{‘name’ : ‘Account’ , ‘placeholder’ : ‘Enter Accountant Name’ , ‘label’ : ‘Account Name’ , ‘type’ : ‘string’ , ‘mode’: ‘multiline’}
and the class look like this
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";
}
I am getting error in this line.
var list = JsonConvert.DeserializeObject(d);
I have checked the Newtonsoft.Json doucument and found a example when i copy the example and replace with my keys and static values. It works fine. string from example look like this.
var c= @"{'name': '[email protected]', 'type': 'string', 'label': 'Name', 'placeholder':'Enter Name', 'mode': 'multiline'}";
When i validate my json string in json validator online it validated properly except it replace my ' ' to " " but i have used ' ' because it is used like this in Newtonsoft.Json example.
I am reading my json string template from word file. My json looks like this in text visulazar.
Please help.
I created this issue in fiddle, Please check https://dotnetfiddle.net/BTma0B
Upvotes: 4
Views: 34205
Reputation: 11
I got the same error, because there was issue in AppSettings.json file.
"AllowedHosts": "*", ----> Some invalid statement here was causing the issue.
Upvotes: 0
Reputation: 1456
For me, there was an issue with the quotes. Accidentally, I have not put quotes at the start & at the end of the parameter I had double quotes. Removing the double quotes at the end fixed the issue.
Either you have to put double quotes on both sides or don't put them at both sides of the parameter.
Upvotes: 0
Reputation: 41
Looks like you are having smart quotes instead of the normal quotes.
I tried the following with normal quotes on the server side
{
"name":"Account",
"placeholder":"Enter Accountant Name",
"label":"Account Name",
"type":"string",
"mode":"multiline"
}
and this works fine.
Can you verify by changing the quotes if that works for you?
Upvotes: 4