I’m using System.Web.Script.Serialization.JavaScriptSerializer, is there any whay that I can ‘cast’ the property’s name to parse JSON to my object? For example:
Case 1: This is my JSON:
{“o”:{“name” : “Tom”, “age” : 22}}
Case 2:
{“o”:{“nickname” : “Tom”, “age” : 22}}
and here is my class:
class Test {
public string name {get; set; }
public int age {get; set; }
}
class MyObj {
public Test data {get; set; }
}
Can any way to parse both of the JSON string in case 1 and case 2 to the instance of MyObj?
Thank you!
One option would be to do a search and replace on the returned JSON string, and replace “nickname” with “name” although that’s not exactly elegant.