Invalid property identifier character: ‘. Path '', line 1, position 1 when parsing json string to object
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?
Related videos on Youtube
Mohit Lohani
Updated on June 04, 2022Comments
-
Mohit Lohani almost 2 years
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
-
Joe Sewell over 3 yearsYour first JSON string looks like it has smart-quote characters instead of "normal" quotes. E.g., you have ‘ and ’, but both of them should be the ' character.
-
Muzaffer Galata over 3 yearsI have tried your sample and got no error. dotnetfiddle.net/UCtYTv
-
Mohit Lohani over 3 years@JoeSewell I have tried with "normal" quotes and ' ' both but still having same issue. The reason of using ' ' is because ' ' mentioned in Newtonsoft.Json. Also when i use static json string with ' ' works fine.
-
Mohit Lohani over 3 years@MuzafferGalata when i use static string like you have used in example it works fine. I get my string by reading a word file and then using regex to fetch this particular pattern. My dynamic json string look like this {‘name’ : ‘Account’ , ‘placeholder’ : ‘Enter Accountant Name’ , ‘label’ : ‘Account Name’ , ‘type’ : ‘string’ , ‘mode’: ‘multiline’}
-
Muzaffer Galata over 3 yearsAny chance to create just a little fiddle sample?
-
Mohit Lohani over 3 years@MuzafferGalata Please check dotnetfiddle.net/BTma0B I have console both the strings i am getting but object not creating
-
Muzaffer Galata over 3 yearsDid you check your string ss?
{‘name’ : ‘Account' , ‘placeholder’ : ‘Enter Accountant Name’, ‘label’ : ‘Account Name’ , ‘type’ : ‘string’ , ‘mode’: ‘multiline’} {‘name’ : ‘Account’ , ‘placeholder’ : ‘Enter Accountant Name’ , ‘label’ : ‘Account Name’ , ‘type’ : ‘string’ , ‘mode’: ‘multiline’}
This is not a valid TemplateModel object. -
Mohit Lohani over 3 years@MuzafferGalata why ? I just also noticed one thing that the smart-quotes around my keys and values are not actually smart-qoute if i replace this with smart-quote. it works iin js fiddle. I am reading string from word so i think it is converting quote to something else. Are you pointing the same thing ?
-
-
Mohit Lohani over 3 yearsNot working. Already tried this with both smart quotes and normal quotes but same error.