c# - Is it possible to add fields with invalid characters to a .net AnonymousType? -
i'm trying send json message facebook call game.achievement wanted create object using anonymoustype before posting. problem 1 of fields "game:points" (with colon). can see i've used @ prefix object field doesn't work game:points field. gets underlined in red , won't compile.
var paramsjson = new { privacy = new { value = "all_friends" }, @object = new { app_id = "my app id", type = "game.achievement", title = "test", @"game:points" = 100, description = "test", image = "img.png" } };
i've tried many varieties of @, double quotes etc. possible or need use stringbuilder this?
why don't use dictionary?
var postdata = new dictionary<string, object> { {"game:points", 100} }
presumably you're going have serialize object post regardless of how it's constructed. serializing json result in same structure. alternatively, other's have suggested , create class payload. can use newtonsoft indicate alternative names serialization.
public class gameachievement { [jsonproperty("game:points")] public int points {get; set;} }
Comments
Post a Comment