json.net

Pass javascript array to C# via json

心不动则不痛 提交于 2019-12-07 18:52:31
问题 I´m using this javascript array: var exportOptions = [{ jobName: ""}, {exportType: ""}, {attachToEmail: ""}, {distributorName: ""}, {vistaNumber: ""}, {customerName: ""}, {competitors: ""}, {agreementType: ""}, { annualPotential: "" }, {businessCase: "" }]; And I passing to ASP.NET codebehind(C#) with this code: $.ajax({ type: 'POST', url: 'Epad.aspx/generateReport', data: "{'columnList': '" + columnList + "', 'exportOptions':" + JSON.stringify( exportOptions ) + "}", contentType:

JSON.Net - DeserializeObject Format

久未见 提交于 2019-12-07 17:58:27
问题 I'm using JSON.Net to try and deserialize some survey responses from SurveyGizmo. Here's a snapshot of the data I'm reading in: {"result_ok":true, "total_count":"44", "page":1, "total_pages":1, "results_per_page":50, "data":[ {"id":"1", "contact_id":"", "status":"Complete", "is_test_data":"0", "datesubmitted":"2011-11-13 22:26:53", "[question(59)]":"11\/12\/2011", "[question(60)]":"06:15 pm", "[question(62)]":"72", "[question(63)]":"One", "[question(69), option(10196)]":"10", I've setup a

deserialize json string depending on type

老子叫甜甜 提交于 2019-12-07 17:47:25
问题 Having json strings like this (I have no control over the publisher): { "TypeName": "Type1" } { "TypeName": "Type1" } Is this an acceptable way to deserialize the json strings dynamically?: public class DeserializationFactory { public static IPoco GetEvent(string jsonString) { var o = JObject.Parse(jsonString); IPoco poco = null; switch (o["TypeName"].ToString()) { case "Type1": poco = JsonConvert.DeserializeObject<Type1>(jsonString); break; case "Type2": poco = JsonConvert.DeserializeObject

ASP.NET WebAPI 2 deserializing JSON sets some nested objects to null

主宰稳场 提交于 2019-12-07 17:44:15
问题 I am encountering an issue while sending some JSON from an AngularJS application to a ASP.Net WebAPI 2 back-end. What happens is that some properties from the incoming request are set to null during deserialization. Part of the request where the deserialization bug occurs: 12: {row: 9, column: 1, order: 13,…} column: 1 domainEntityProperty: {$id: "157", id: 2616,…} order: 13 renderType: {$id: "39", id: 1, class: "input"} row: 9 Above snippet is piece of the request that is being sent. It's a

Can I Use Json.Net de-serialization by default with ASP.net Web Api and MVC 3?

坚强是说给别人听的谎言 提交于 2019-12-07 17:29:24
I have a MVC 3 web application/ API that I am using and I am woefully tired of the default Microsoft Serialization. The big promise of the new ASP.net Web Api in MVC 4 is that it will use JSON.net de-serialization by default. Well I would love to use JSON deserialization by default and not mess with the WCF client. One issue I do have is I cannot convert to MVC 4 for various reasons. So my question is can I still use the Json.net deserialization by default with MVC 3? What I am trying to do specifically is implement a Json Converter to handle inheritance of objects I am de-serializing. So that

Can I parse json either into a string or another concrete type as object?

混江龙づ霸主 提交于 2019-12-07 16:59:24
问题 I'd like to have property of type object that can be either a string or Template type. Is it possible to tell Json.NET to parse something into one of several specified types? class MyClass { public object Template { get; set; } } where Template = "TemplateName" { "Template": "TemplateName" } or Template = new Template() { "Template": { "Name": "OtherTamplate", ... } } UPDATE: I tried to follow @krillgar' advice and create a custom JsonConverter but unfortunatelly the CanConvert method

Why have warning Newtonsoft.Json.JsonConvert.DeserializeObjectAsync

ⅰ亾dé卋堺 提交于 2019-12-07 16:45:57
问题 I'm using JSON.NET version 6.0.1 and here my code below var text = await FileHelper.ReadFileAsync(folderSetting, fileName); var items = await JsonConvert.DeserializeObjectAsync<ObservableCollection<ItemModel>>(text); But my Visual Studio Warning Warning 7 'Newtonsoft.Json.JsonConvert.DeserializeObjectAsync(string)' is obsolete: 'DeserializeObjectAsync is obsolete. Use the Task.Factory.StartNew method to deserialize JSON asynchronously: Task.Factory.StartNew(() => DeserializeObject(value))'

Serializing in Azure Function

依然范特西╮ 提交于 2019-12-07 16:23:14
问题 I'm running into a strange issue with Azure Function Apps. Newtonsoft Json.NET deserialization is not liking the $type annotations. My deserialization code looks like: return JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); The json looks like: { "$type": "Trading.Control.Json.TradingConfig, Trading", "Config": { "$type": "Trading.Control.Json.Config, Trading", "Optimize": false }, "Trading": { "$type": "System.Collections

How do I convert a complex json object to CLR object with json.net?

折月煮酒 提交于 2019-12-07 15:29:22
sorry for a dumb question but I haven't found any solution for this. Here is my JSON: { "Id": "1", "Parent.Id": "1", "Agent.Id": "1", "Agent.Profile.FullName": "gena", "Fee": "10.1200", "FeeManagementDate": "29/11/2013", "Contact.Name": "Genady", "Contact.Telephone": "000000000", "Contact.Email": "gena@email.com", "AgreementUrl": "http://www.test.com/agreement" } Here is my object public class ManagementDetailsViewModel : ViewModel<int> { public ManagementDetailsViewModel() { } public string AgreementUrl { get; set; } public HttpPostedFileBase AgreementFile { get; set; } public decimal Fee {

Conditionally deserialize JSON string or array property to C# object using JSON.NET? [duplicate]

寵の児 提交于 2019-12-07 15:24:34
问题 This question already has answers here : How to handle both a single item and an array for the same property using JSON.net (7 answers) Closed 3 years ago . I have a defined C# object based off a very complex JSON I'm getting from a third party API. Here's a piece of it: {"alarmSummary":"NONE"} The corresponding property in C# would be: public string alarmSummary {get; set;} And I would get this converted by using my typical JSONConvert from JSON.NET: var alarms = JSONConvert