Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

c#

json.net

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

like image 708
Mohit Avatar asked Oct 17 '25 00:10

Mohit


1 Answers

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?

like image 104
Afterlife Avatar answered Oct 19 '25 15:10

Afterlife