0

I can't convert the JSON object below to class in Asp.Net MVC

{
  "Name.Test":"fsafasfda"
}

Any suggestions are appreciated.

The scenario is like this in asp.net action:

[HttpPut]        
public JsonResult Test(NameRootobject obj)
{

}

the the class was paste JOSN as class:

class NameRootobject 
{

    public string NameTest{get;set;}

}

But the NameTest property is null.

How to resolve this problem?

4
  • what do you want to do exactly?your question is not clear!. Commented Dec 27, 2016 at 10:56
  • 1
    As said, the question is unclear, please elaborate what are you trying to do and what have you tried, add minimal reproducible example to your question. Commented Dec 27, 2016 at 11:03
  • I'd like to Deserialize the json string to an object, but I can't define the class. Commented Dec 27, 2016 at 11:06
  • Please edit your question and add the code you are having trouble with. Commented Dec 27, 2016 at 11:10

1 Answer 1

1

Use the JsonProperty attribute on the class so the framework knows how to deal with that property name

public class NameRootobject {
    [JsonProperty("Name.Test")]
    public string NameTest { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.