json.net

Deserializing json into object: wrapper class workaround

梦想与她 提交于 2019-12-23 12:38:23
问题 This is my json { "accessType":"Grant", "spaces":[{"spaceId":"5c209ba0-e24d-450d-8f23-44a99e6ae415"}], "privilegeId":"db7cd037-6503-4dbf-8566-2cca4787119d", "privilegeName":"PERM_RVMC_DEV", "privilegeDescription":"RVMC Dev", "privilegeType":"Permission" } And here's my class: public class ProfilePrivilege { public AccessType AccessType { get; set; } public Guid PrivilegeId { get; set; } public string PrivilegeName { get; set; } public string PrivilegeDescription { get; set; } public

Json.NET Ignore null values in dictionary

南笙酒味 提交于 2019-12-23 12:17:14
问题 When serializing a dictionary with JSON.NET, it seems like the NullValueHandling setting is ignored. var dict = new Dictionary<string, string> { ["A"] = "Some text", ["B"] = null }; var json = JsonConvert.SerializeObject(dict, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Console.WriteLine(json); Output: { "A": "Some text", "B": null } I expected that only the KVP with key "A" is present in the json output and KVP "B" is omitted. How can I

Receiving Json deserialized object as string in Web API controller

陌路散爱 提交于 2019-12-23 12:06:09
问题 Following is my Json input from Ui: { "data": [{ "Id": 1 }, { "Id": 2 }, { "Id": 3 }] } I can receive it without an issue in the object structure shown below: public class TestController : ApiController { /// <summary> /// Http Get call to get the Terminal Business Entity Wrapper /// </summary> /// <param name="input"></param> /// <returns></returns> [HttpPost] [Route("api/TestJsonInput")] public string TestJsonInput([FromBody] TestInput input) { return JsonConvert.SerializeObject(input.data)

Error in deserialising the objects

寵の児 提交于 2019-12-23 12:04:46
问题 I have a JSON string. [ { "target":"FDOL00001", "datapoints":[ { "y":72.564, "x":1523858700 } ] }, { "target":"FDOL00001", "datapoints":[ { "y":86.366, "x":1523858700 } ] }, { "target":"FDOL00001", "datapoints":[ { "y":73.90195818815343, "x":1523858700 } ] } ] I am trying to deserialise it to a collection. But I am getting an error. Can somebody direct me to the right way to fix this? class datapoint { [JsonProperty("x")] public int x { get; set; } [JsonProperty("y")] public decimal y { get;

Doubly Linked List to JSON

我们两清 提交于 2019-12-23 11:59:44
问题 I've a three dimensional structure ... actually a doubly linked list with six nodes i.e. left, right, up, down, in, out. if one node is on the right side of other then that node will be defiantly on the left side of the first one. like Actually this is a 3D structure, but for understanding purposes, I've given a 2D example. Now I've to convert it in JSON format, to send this data through WCF to a client, but as it contains loops so it couldn't be converted to JSON. I've these questions Can

Doubly Linked List to JSON

孤街浪徒 提交于 2019-12-23 11:59:00
问题 I've a three dimensional structure ... actually a doubly linked list with six nodes i.e. left, right, up, down, in, out. if one node is on the right side of other then that node will be defiantly on the left side of the first one. like Actually this is a 3D structure, but for understanding purposes, I've given a 2D example. Now I've to convert it in JSON format, to send this data through WCF to a client, but as it contains loops so it couldn't be converted to JSON. I've these questions Can

JArray.Contains issue

对着背影说爱祢 提交于 2019-12-23 10:40:34
问题 I have a JArray, read from a file : private void RemoveCatalog(Catalog catalog) { System.IO.StreamReader filereader = new System.IO.StreamReader(@appDirectory + "\\list"); JArray myjarray = JArray.Parse(filereader.ReadToEnd()); filereader.Close(); string json = " {\"token\":\"" + catalog.Token + "\",\"name\":\"" + catalog.Name +"\",\"logo\":\"" + catalog.Logo + "\",\"theme\":\"" + catalog.Theme + "\"}"; JObject myCatalogAsJObject = JObject.Parse(json); myjarray.Remove(myCatalogAsJObject); } I

Unable to deserialize an object with a byte array property using Json.NET 8.0.1

馋奶兔 提交于 2019-12-23 10:29:50
问题 After upgrading a code base to use Json.NET 8.0.1, some deserialization stumbles. Using Json.NET 7.0.1 everything works fine. Apparently it is the deserialization of a property of type byte[] that causes the problem. If I remove the byte[] property it works fine. I can reproduce the behavior using this simple console application: internal class Program { private static void Main(string[] args) { Dictionary<string, Account> accounts; var jsonSerializerSettings = new JsonSerializerSettings {

How to remove escape characters from a JSON String

六眼飞鱼酱① 提交于 2019-12-23 10:28:35
问题 I called a REST API with the following JSON string returned: "{\"profile\":[{\"name\":\"city\",\"rowCount\":1,\"location\": ............ I tried to remove escape character with the following code before I deserialize it: jsonString = jsonString.Replace(@"\", " "); But then when I deserialize it, it throws an input string was not in a correct format : SearchRootObject obj = JsonConvert.DeserializeObject<SearchRootObject>(jsonString); The following is the complete code: public static

JSON to C# — list fields without sub-field names in json?

心不动则不痛 提交于 2019-12-23 09:50:29
问题 Using Json.net (Newtonsoft.json), how can I define a C# class (or classes) to handle the json below? The 'data' field appears to be a list of level/description sub-fields but note they are not preceded by field names. The 'error' field appears to be a list of error-number/error-message sub-fields but note, they too, are not preceded by field names. { "status": "error", "data": [ { "warning" : "your input was wrong" } ], "error": [ { "373": "Error description goes here" } ] } This class