json.net

Serializing/Deserializing Dictionary of objects with JSON.NET

半世苍凉 提交于 2019-12-28 03:45:05
问题 I'm trying to serialize/deserialize a Dictionary<string, object> which seems to work fine if the object is a simple type but doesn't work when the object is more complex. I have this class: public class UrlStatus { public int Status { get; set; } public string Url { get; set; } } In my dictionary I add a List<UrlStatus> with a key of "Redirect Chain" and a few simple strings with keys "Status", "Url", "Parent Url". The string I'm getting back from JSON.Net looks like this: {"$type":"System

Newtonsoft.Json deserialize object in Xamarin iOS project

扶醉桌前 提交于 2019-12-28 03:14:04
问题 I'm getting some very weird behaviour in my Xamarin.Forms Project. I'm retrieving some serialized data from a REST API. I'm then trying to use Json.NET to deserialize that to an object. This works perfectly fine on Android and if I copy the code to a .NET console application it also works. However in my iOS project, the call to .DeserializeObject() just returns null. It doesn't throw an error or complain in any way. I did find this discussion: https://forums.xamarin.com/discussion/15152

Newtonsoft.Json deserialize object in Xamarin iOS project

♀尐吖头ヾ 提交于 2019-12-28 03:13:12
问题 I'm getting some very weird behaviour in my Xamarin.Forms Project. I'm retrieving some serialized data from a REST API. I'm then trying to use Json.NET to deserialize that to an object. This works perfectly fine on Android and if I copy the code to a .NET console application it also works. However in my iOS project, the call to .DeserializeObject() just returns null. It doesn't throw an error or complain in any way. I did find this discussion: https://forums.xamarin.com/discussion/15152

JSON.NET Serializer for WCF REST Services

寵の児 提交于 2019-12-28 02:59:25
问题 I am trying to use the NETFx Json.NET MediaTypeFormatter nuget package to swap out the default DataContractJsonSerializer in my WCF REST service (4.0 framework). I downloaded the package in my project and added the following lines of code in the Global.asax file. void Application_Start(object sender, EventArgs e) { RegisterRoutes(); // Create Json.Net formatter serializing DateTime using the ISO 8601 format var serializerSettings = new JsonSerializerSettings(); serializerSettings.Converters

Is there a way in Json.NET serialization to distinguish between “null because not present” and “null because null”?

蹲街弑〆低调 提交于 2019-12-28 02:56:04
问题 I'm working in an ASP.NET webapi codebase where we rely heavily on the automatic support for JSON deserialization of message bodies into .NET objects via JSON.NET. As part of building out patch support for one of our resources, I'd very much like to distinguish between an optional property in the JSON object that's not present, vs. that same property that's explicitly to null. My intention is to use the first for "don't change what's there" vs. "delete this thing." Does anyone know if it's

JSON.NET deserialize a specific property

匆匆过客 提交于 2019-12-28 02:51:32
问题 I have the following JSON text: { "PropOne": { "Text": "Data" } "PropTwo": "Data2" } I want to deserialize PropOne into type PropOneClass without the overhead of deserializing any other properties on the object. Can this be done using JSON.NET? 回答1: public T GetFirstInstance<T>(string propertyName, string json) { using (var stringReader = new StringReader(json)) using (var jsonReader = new JsonTextReader(stringReader)) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken

How to return JSon object

℡╲_俬逩灬. 提交于 2019-12-28 02:07:51
问题 I am using a jQuery plugin that need a JSON object with following structure(I will be retrieving the values from database): { results: [ { id: "1", value: "ABC", info: "ABC" }, { id: "2", value: "JKL", info: "JKL" }, { id: "3", value: "XYZ", info: "XYZ" } ] } Here is my class: public class results { int _id; string _value; string _info; public int id { get { return _id; } set { _id = value; } } public string value { get { return _value; } set { _value = value; } } public string info { get {

How to return JSon object

别等时光非礼了梦想. 提交于 2019-12-28 02:07:26
问题 I am using a jQuery plugin that need a JSON object with following structure(I will be retrieving the values from database): { results: [ { id: "1", value: "ABC", info: "ABC" }, { id: "2", value: "JKL", info: "JKL" }, { id: "3", value: "XYZ", info: "XYZ" } ] } Here is my class: public class results { int _id; string _value; string _info; public int id { get { return _id; } set { _id = value; } } public string value { get { return _value; } set { _value = value; } } public string info { get {

JsonConvert.DeserializeObject<> (string) returns null value for $id property

随声附和 提交于 2019-12-28 01:33:12
问题 I'm downloading the JSON using System.Net.WebClient.DownloadString. I'm getting a valid response: { "FormDefinition": [ { "$id":"4", "Class":558, "ClassDisplayLabel":"Punchworks", "Name":"Punchworks Form" }, { "$id":"6", "Class":558, "ClassDisplayLabel":"Punchworks", "Name":"Punchworks Form test second" }, { "$id":"46", "Class":558, "ClassDisplayLabel":"Punchworks", "Name":"any_Name" }, { "$id":"47", "Class":558, "ClassDisplayLabel":"Punchworks", "Name":"Punchworks Form test second" }, { "$id

How does JSON deserialization in C# work

牧云@^-^@ 提交于 2019-12-28 01:00:31
问题 I am trying to understand how JsonConvert.DeserializeObject<X>(someJsonString) is able to set the values by using the constructor. using Newtonsoft.json public class X { [JsonProperty("some_Property")] public string SomeProperty {get;} [JsonProperty("some_Property_2")] public string SomeProperty2 {get;} public X(string someProperty, string someProperty2) { SomeProperty = someProperty; SomeProperty2 = someProperty2; } public static X parseObject(string parseThisJson) { JsonConvert