json.net

WebApi bind body to Json dictionary

半腔热情 提交于 2019-12-20 05:43:09
问题 I'm trying to create a WebApi action method with the following signature: [System.Web.Http.HttpPost] public object Execute([FromUri] string command, [FromUri] string method, [FromBody] IDictionary<string, JToken> arguments) However, when I hit this method with requests, arguments never binds correctly (the two URI fields do). The ModelState shows a Json.NET parse error at the first character. I've tried request bodies that look like: id=50 and arguments={ "id": 50 } . How do I have to

Using System.Type as <T> at runtime when deserializing with Json.Net

ぐ巨炮叔叔 提交于 2019-12-20 05:15:04
问题 I have a process that needs to be able to call on a function in the following manner. public static Task<string> Convert(string payload, Type type) { JsonSerializerSettings settings = new JsonSerializerSettings().Configure();//<--- Pull in extension methods to handle custom types return JsonConvert.SerializeObject(JsonConvert.DeserializeObject<type>(payload), settings)); } The code above does not compile. Next, I used John Skeet's answer to a 2011 question similar to mine. public static

Using System.Type as <T> at runtime when deserializing with Json.Net

依然范特西╮ 提交于 2019-12-20 05:14:28
问题 I have a process that needs to be able to call on a function in the following manner. public static Task<string> Convert(string payload, Type type) { JsonSerializerSettings settings = new JsonSerializerSettings().Configure();//<--- Pull in extension methods to handle custom types return JsonConvert.SerializeObject(JsonConvert.DeserializeObject<type>(payload), settings)); } The code above does not compile. Next, I used John Skeet's answer to a 2011 question similar to mine. public static

handling name space changes during deserialization of JSON String

徘徊边缘 提交于 2019-12-20 05:02:12
问题 I have 2 applications that are communicate amongst each other with the help of a redis Server, In my first application i am able to serialize and de serialize and object of the following type { "$type": "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib], [OPCMessagingService.Resource, OPCMessagingService]], mscorlib", "71": { "$type": "OPCMessagingService.Resource, OPCMessagingService", "SiteID": 2, "ResourceID": 71, "ProcessOrder": "001000380873", "CurrentStatus": 0,

json serializer NullValueHandling without use datamember attribute

醉酒当歌 提交于 2019-12-20 04:55:12
问题 In my Web api project, Right now I'm skipping null values. therefore, the return json ignores null values and prints the property. In Global.asax file: //manage the null in the response var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; However, I want to replace the null values by "-". but, i dont want to use data member attribute for each property... [DefaultValue("-")]. i have more

Deserializing just a single node of a JSON response

点点圈 提交于 2019-12-20 04:52:40
问题 I have a json response like { "appStatus":{ "status":true }, "lastSyncDate":"06-07-2013 13.54.27", "configResponse":{ "status":{ "status":true }, "configs":{ "APPLOGENABLED":{ "configCode":"APPLOGENABLED", "configDesc":"enable or disable logging from front end", "configType":"TAB", "configValue":"Y" }, "COMMENTSTIMER":{ "configCode":"COMMENTSTIMER", "configDesc":"timer for comments in seconds", "configType":"TAB", "configValue":"60" }, "SUMMARYTIMER":{ "configCode":"SUMMARYTIMER", "configDesc

Google's OpenIDConnect return a Base64 token that cannot be parsed

怎甘沉沦 提交于 2019-12-20 04:37:22
问题 As exercise to understand OpenIDConnect, I am trying to authenticate in my web app with Google following this guide. The problem is I cannot read the token that Google sends to my application> var bytes = Convert.FromBase64String(codeEx.Id_token); var token = Encoding.ASCII.GetString(bytes); It fails in the first line saying: "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."

How to ignore base class JsonConverter when deserializing derived classes?

眉间皱痕 提交于 2019-12-20 04:36:42
问题 I have an abstract base class: [JsonConverter(typeof(Converter))] public abstract class TextComponent { ... public bool Bold { get; set; } public TextComponent[] Extra { get; set; } ... } And more classes which inherits from it. One of those classes is StringComponent : public sealed class StringComponent : TextComponent { public string Text { get; set; } public StringComponent(string text) { Text = text; } } Converter , which is a JsonConverter applied to TextComponent looks like this:

Which encoding should I specify for the serialized data from TextBox controls

╄→尐↘猪︶ㄣ 提交于 2019-12-20 04:23:15
问题 Suppose that I have a TextBox in my WinForms application. When user clicks a button, the application should send a serialized value stored in this TextBox via TCP. For the serialization I'm using Newtonsoft.Json library like this: string json = JsonConvert.SerializeObject(credentials); Where credentials is the object of class that holds TextBox 's value. Then I need to send it over network via TcpClient class: TcpClient client = new TcpClient(IpAddress, Port); NetworkStream stream = client

How to deserialize collection of interfaces when concrete classes contains other interfaces

ぃ、小莉子 提交于 2019-12-20 04:22:49
问题 I am currently facing the situation where I get a json file that I can't modify and I want the resulting deserialized class to be generic for design purpose. First here are my interfaces : public interface IJobModel { string ClientBaseURL { get; set; } string UserEmail { get; set; } ExportType Type { get; set; } List<IItemModel> Items { get; set; } } public interface IItemModel { string Id { get; set; } string ImageSize { get; set; } string ImagePpi { get; set; } List<ICamSettings>