can't get json.NET to deserialize and show my values in c#
Please help I can't get the values out after user json.NET
Here is the string that I get back from my jquery ajax call:
"[{\"roleInfo\":{\"roleIndex\":0,\"roleID\":\"c1_r0_23\",\"roleName\":\"Chief Executive\"}}, {\"role开发者_运维技巧Info\":{\"roleIndex\":1,\"roleID\":\"c1_r1_192\",\"roleName\":\"Chief Operating Officer\"}}]"
Here is the webmethod that exists in my code behind on my aspx page:
List md1 = (List)Newtonsoft.Json.JsonConvert.DeserializeObject(sv, typeof(List));
This is my class for MappedRole: public class MappedRole {
public int roleIndex { get; set; }
public int roleID { get; set; }
public string roleName { get; set; }
public MappedRole(){
}
}
These are the values that I get after trying to use JsonConvert.DeserializeObject....notice that I get null and 0 values: I try to see the values while in debug mode.
?md1[0].roleID 0 ?md1[0].roleName null ?md1[0].roleIndex 0
Have you tried to run the JSON through the JSON Validator? I ran your sample from your question and it's not validating. Here's the url to the validator: http://jsonlint.com/
精彩评论