3

I want to map an object to a different property name when deserializing with Newonsoft Json. I have found the answer both here on SO and in their official documentation to use [JsonProperty("name")] but when I use this code I get the following error:

Constructor 'JsonPropertyAttribute' has 0 parameter(s) but is invoked with 1 argument(s)

What am I doing wrong? I can build the project but I can't get rid of the red squiggly line.

public class Test
{
    [JsonProperty("name")]
    public string TestName { get; set; }
}

enter image description here

Community
  • 1
  • 1
Ogglas
  • 62,132
  • 37
  • 328
  • 418

1 Answers1

0

Try to specify value to PropertyName property of JsonPropertyAttribute instead

[JsonProperty(PropertyName = "name")]
Adnan Umer
  • 3,669
  • 2
  • 18
  • 38
  • Tried this already, I get the error "Cannot resolve symbol 'PropertyName'" – Ogglas May 02 '16 at 13:32
  • Might b there is another attribute defined with same name. Try this `[Newtonsoft.Json.JsonProperty(PropertyName = "name")]` – Adnan Umer May 02 '16 at 13:33
  • Get latest version of `Newtonsoft.Json`, Clean & Rebuild Solution – Adnan Umer May 02 '16 at 13:39
  • I did all of the above but I still have the same error. I can however build the project without a problem but I can't get rid of the red squiggly line – Ogglas May 02 '16 at 13:47
  • 1
    JsonPropertyAttribute(String) Initializes a new instance of the JsonPropertyAttribute class with the specified name. – Amit Kumar Ghosh May 02 '16 at 13:47
  • @Ogglas Close VS, delete `bin` & `obj` directories within all projects and then start VS, Rebuild solution. Hope that will solves the problem – Adnan Umer May 02 '16 at 13:59
  • @AdnanUmer and clear out the Resharper cache if integrated within VS. – bvj Oct 15 '18 at 07:08