Invalid property identifier character: ‘. Path '', line 1, position 1 when parsing json string to object

13,827

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?

Share:
13,827

Related videos on Youtube

Mohit Lohani
Author by

Mohit Lohani

Updated on June 04, 2022

Comments

  • Mohit Lohani
    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.

    https://ibb.co/XjWrmS7

    Please help.

    I created this issue in fiddle, Please check https://dotnetfiddle.net/BTma0B

    • Joe Sewell
      Joe Sewell over 3 years
      Your 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
      Muzaffer Galata over 3 years
      I have tried your sample and got no error. dotnetfiddle.net/UCtYTv
    • Mohit Lohani
      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
      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
      Muzaffer Galata over 3 years
      Any chance to create just a little fiddle sample?
    • Mohit Lohani
      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
      Muzaffer Galata over 3 years
      Did 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
      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
    Mohit Lohani over 3 years
    Not working. Already tried this with both smart quotes and normal quotes but same error.