2

Find below the json response...

{
"personalDetails": {
    "Name ": " Taeyeon",
    "Date Of Birth ": " 03/09/1989",
    "Zodiac ": " Pisces"
},
"education": {
    "High School ": " Jeonju Art High school ",
    "University ": " -"
}

}

My Class is here

    public class Biography
{
    public personalDetails personalDetails { get; set; }
    public education education { get; set; }
    public work work { get; set; }
    public personal personal { get; set; }
}


public class personalDetails
{
    public string Name { get; set; }
    public string DateBirth { get; set; }
    public string Zodiac { get; set; }
}

public class education
{
    public string HighSchool { get; set; }
    public string University { get; set; }
}

Then I put the code:

Biography dataSet = JsonConvert.DeserializeObject<Biography>(e.Result);

It doesn't work because of Arttribute has space. What should I do?

0

3 Answers 3

12

Try adding the JsonProperty attribute. That should work for you.

[JsonProperty(PropertyName = "Date Of Birth ")]
public string DateBirth { get; set; }

[JsonProperty(PropertyName = "High School ")]
public string HighSchool { get; set; }

Edit

I see you have trailing spaces too so updated the attributes above. Do the same for "Name ", etc.

Sign up to request clarification or add additional context in comments.

Comments

0

Download the Json as a string, and use something like myString = myString.Replace(@"High School", "HighSchool"). Do this as the step before deserializing.

Comments

0

For some people this might be helpful:

Add Namespace: using Newtonsoft.Json;

var jsonString = "{" +
    "'personalDetails': {" +
        "'Name ': 'Taeyeon'," +
        "'Date Of Birth ': ' 03/09/1989'," +
        "'Zodiac ': ' Pisces'," +
    "}," +
    "'education': {" +
        "'High School ': ' Jeonju Art High school '," +
        "'University ': ' -'," +
    "}" +
"}";

var json = JsonConvert.DeserializeObject(jsonString);            
return Ok(json);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.