json.net

Deserialization of a Facebook JSON string?

こ雲淡風輕ζ 提交于 2019-12-04 19:22:40
I am not able to get my head around extracting the work_history, affiliations and current_loc of the facebook user from the JSON string that is generated after i run my fql query I have made this class : public class Data { public CurrentLocation current_location { get; set; } public WorkHistory[] work_history { get; set; } public EducationHistory[] education_history { get; set; } } public class EducationHistory { public string name { get; set; } public int? year { get; set; } public string school_type { get; set; } } public class WorkHistory { public string company_name { get; set; } public

DI and JSON.NET

时光毁灭记忆、已成空白 提交于 2019-12-04 18:05:46
问题 I'm using JSON.NET to serialize and deserialize object for different purposes. I'm a big fan of DI but the code below gives me the chills. Is smells like bad code: public class Foo : Baz { private readonly IBar bar; public Foo() : this(ObjectFactory.GetInstance<IBar>()) { } public Foo(IBar bar) { if (bar == null) throw new ArgumentNullException("bar"); this.bar = bar; } ... rest of class ... } The default constructor is the thing that gives me the chills. I've added this to support the

Cannot deserialize xml string with Newtonsoft.Json.JsonConvert.DeserializeObject

…衆ロ難τιáo~ 提交于 2019-12-04 16:48:48
Hi I am passing an xml as string <AbcDto xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Abc"> <Id>2</Id> <Description>sample string 4</Description> <Name>sample string 3</Name> <PolicyId>c17f5b9f-c9bf-4a3a-b09b-f44ec84b0d00</PolicyId> <Status>Active</Status> <TimeZoneId>USCentral</TimeZoneId> </AbcDto> When I am trying creating Custom Model Binder for Web Api public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext) { var json = actionContext.Request.Content.ReadAsStringAsync()

Get values and keys in json object using Json.Net C#

北城以北 提交于 2019-12-04 16:41:53
问题 Hi there I have json that looks like this: { "Id": " 357342524563456678", "title": "Person", "language": "eng", "questionAnswer": [ { "4534538254745646.1": { "firstName": "Janet", "questionNumber": "1.1" } } ] } Now I have written some code that loops over the objects in the questionAnswer array and then gets the name of the object which is 4534538254745646.1 . Now Im trying to save the key of each Item and the value aswell but I am only managing to get the value. How would I do this, here is

Prevent Json.NET 4.5 from appending timezone offset when using MicrosoftDateFormat

纵然是瞬间 提交于 2019-12-04 16:40:31
问题 Short of a custom DateTimeConverterBase implementation, is there some way to keep Json.NET 4.5+, when set to use DateFormatHandling.MicrosoftDateFormat , from appending a timezone offset for any non-UTC DateTime it is given? "\/Date(1333645844276-0600)\/" Details I am switching an API project from using the built-in .NET JavaScriptSerializer to using Json.NET to generate JSON. In Json.NET, for a UTC DateTime , the default datetime serialization was similar to the .NET version: "\/Date

Prevent $id/$ref when serializing objects using Web API and JSON.NET

折月煮酒 提交于 2019-12-04 16:26:51
问题 I can't seem to prevent Web API/JSON.NET from using Newtonsoft.Json.PreserveReferencesHandling.Objects when serializing objects. In other words, $id/$ref are always used in the serialized objects despite using the following settings: public class MvcApplication : System.Web.HttpApplication { protected void Application_Start () { WebApiConfig.Register(GlobalConfiguration.Configuration); } } public static class WebApiConfig { public static void Register (HttpConfiguration config) {

Static property is null after being assigned

拥有回忆 提交于 2019-12-04 16:16:50
问题 I have this code: static class Global { public static readonly IChannelsData Channels = new ChannelsData(); public static readonly IMessagesData Messages = new MessagesData(); } My understanding is that, because this class is static, it is impossible for Global.Channels or Global.Messages to be null now that they have been given an instance. However, I try to access the property with public class Channel : IComparable { ... private SortedList<string, Message> _messages; [JsonConstructor]

C# Manipulating JSON data

爱⌒轻易说出口 提交于 2019-12-04 16:04:29
问题 I have a 'simple' scenario: Read some JSON file, Filter or change some of the values and write the resulting json back without changing the original formatting. So for example to change this: { "type": "FeatureCollection", "crs": { "type": "EPSG", "properties": { "code": 28992 } }, "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [ 149886.192, 374554.705 ], [ 149728.583, 374473.112 ], [ 149725.476, 374478.215 ] ] ] } } ] } Into this: { "type":

Converting dynamic type to dictionary C#

你说的曾经没有我的故事 提交于 2019-12-04 15:57:43
问题 I have a dynamic object that looks like this, { "2" : "foo", "5" : "bar", "8" : "foobar" } How can I convert this to a dictionary ? 回答1: You can use a RouteValueDictionary to convert a C# object to a dictionary. See: RouteValueDictionary Class - MSDN. It converts object properties to key-value pairs. Use it like this: var toBeConverted = new { foo = 2, bar = 5, foobar = 8 }; var result = new RouteValueDictionary(toBeConverted); 回答2: If the dynamic value in question was created via

Parsing dynamic JSON string into string in C# using JSON.NET

自闭症网瘾萝莉.ら 提交于 2019-12-04 15:31:42
This is my first little project on C# and JSON. I'm asked to parse a JSON file into the following: I'm trying to create a windows form whose body will contain the content of a JSON string in the following format: Name of the object (Label) name of the attribute of the object - (TextBox) editable value (Label) name of the attribute of the object - (TextBox) editable value ... I have approx 35 attributes per object in the json file and 8 objects. There are around 50 different attributes in total. I have searched for JSON - C# - JSON.NET and read more than 15 questions & answers. Answers had some