北城已荒凉
2010-02-11 18:30
采纳率: 0%
浏览 365

如何将 JSON 对象转换为自定义 c # 对象?

Is there an easy way to populate my C# Object with the JSON object passed via AJAX?

//This is the JSON Object passed to C# WEBMETHOD from the page using JSON.stringify

{
    "user": {
        "name": "asdf",
        "teamname": "b",
        "email": "c",
        "players": ["1", "2"]
    }
}

//C# WebMetod That receives the JSON Object

[WebMethod]
public static void SaveTeam(Object user)
{

}

//C# Class that represents the object structure of JSON Object passed in to the WebMethod

public class User
{
    public string name { get; set; }
    public string teamname { get; set; }
    public string email { get; set; }
    public Array players { get; set; }
}

转载于:https://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object

13条回答 默认 最新

相关推荐 更多相似问题