json.net

How to prevent or allow json serialization of a property from breeze controller

邮差的信 提交于 2019-12-25 07:16:27
问题 So it happens that you can prevent breeze json serialization of some properties using data annotations on your model by like this(well if you are using EF6 with JSON.NET on the backend)... [Table("Project")] public partial class Project { public Project() { } public int id { get; set; } [JsonIgnore] public bool NoLongerExist { get; set; } } By doing so the property becomes invisible on this endpoint used by breeze public IQueryable<Project> Projects() { return _db.Context.Projects.Where(o =>

Serializing a list of interface objects

可紊 提交于 2019-12-25 07:16:20
问题 Using Json.net, I want to deserialize a basket containing interface objects. This... { "Owner": "John", "Fruit": [ <an apple object>, <a pear>, etc... ] } ... should go into this... class Basket { string Owner; List<iFruit> Fruit; //contains instances of Apple, Pear,... } Interfaces cannot be instantiated, so a conversion to concrete objects is needed. I found examples using a JsonConverter to create concrete Apple and Pear instances. But the list is always created directly with a line like:

Deserialize a nested DataSet from Json String with Json.NET

旧巷老猫 提交于 2019-12-25 06:09:10
问题 I try to deserialize a DataSet from a JSON String with Json.NET. The Json String contents a status, message and the table that I want to use: { "status": "ok", "message": "", "table": [{ "column1": "value1", "column2": "value2" }, { "column1": "value3", "column2": "value4" }] } Here my source: public class RequestResult { public string status { get; set; } public string message { get; set; } } ... var serializer = new JsonSerializer(); var sr = new StreamReader(response.GetResponseStream())

Deserialize a nested DataSet from Json String with Json.NET

笑着哭i 提交于 2019-12-25 06:09:01
问题 I try to deserialize a DataSet from a JSON String with Json.NET. The Json String contents a status, message and the table that I want to use: { "status": "ok", "message": "", "table": [{ "column1": "value1", "column2": "value2" }, { "column1": "value3", "column2": "value4" }] } Here my source: public class RequestResult { public string status { get; set; } public string message { get; set; } } ... var serializer = new JsonSerializer(); var sr = new StreamReader(response.GetResponseStream())

DeSerializing JSON returns null C#

不打扰是莪最后的温柔 提交于 2019-12-25 04:48:18
问题 I have following JSON that I'm trying to deserialize. { "output-parameters":[ { "value":{ "array":{ "elements":[ { "string":{ "value":"cp-100" } }, { "string":{ "value":"cp-101" } }, { "string":{ "value":"cp-100" } }, { "string":{ "value":"cp-101" } }, { "string":{ "value":"cp-100" } } ] } }, "type":"Array/string", "name":"Tags", "scope":"local" }, { "value":{ "string":{ "value":"subscribed" } }, "type":"string", "name":"Error", "scope":"local" } ] } I have created following classes to bind

ASP.NET MVC Controller cannot return HttpResponseMessage correctly with streamed content

好久不见. 提交于 2019-12-25 04:46:10
问题 Just as the title says I am not getting the MVC Controller to return HttpResponseMessage correctly. [HttpGet] [AllowAnonymous] public HttpResponseMessage GetDataAsJsonStream() { object returnObj = new { Name = "Alice", Age = 23, Pets = new List<string> { "Fido", "Polly", "Spot" } }; var response = Request.CreateResponse(HttpStatusCode.OK); var stream = new MemoryStream().SerializeJson(returnObj); stream.Position = 0; response.Content = new StreamContent(stream); response.Content.Headers

Why JsonConverter.WriteJson() never gets called, although JsonConverter.ReadJson() does get called?

不羁的心 提交于 2019-12-25 04:09:27
问题 Why my custom JsonConverter.WriteJson() method doesn't get called ? class MyType{ [JsonConverter(typeof(DocumentXamlDeserializer))] public string GuiData { get; set; } public string SimpleString; } Although the ReadJson does get called: public class DocumentXamlDeserializer : JsonConverter { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteValue(Gui.Handler.SerializeData()); } public override object ReadJson(JsonReader reader, Type

Using Json.NET to parse result returned by Google Maps API

偶尔善良 提交于 2019-12-25 03:58:09
问题 I am trying to use google map api's web service to make a web request, and get the json string, and then get the latitude and longitude I need for the input address. Everything is fine. I got the json string I need. Now I am using Json.net to parse the string. I don't know why, but I simply cannot convert it into a JArray . Here is the json string Can anyone teach me how to write the c# code to get the lat and lng in geometry > location ? Thanks Here is my codes and the bug screenshot 回答1:

Json.NET not call my custom converter if that value is null

。_饼干妹妹 提交于 2019-12-25 03:56:24
问题 I am stuck with this problem for a day. The custom converter that I created will convert null string to empty string. I found that if the string has null value Json.NET not call my converter. I 've tried to setting everything that I can but Json.NET still not send that null string to custom converter. This is my converter code using System; using Newtonsoft.Json; using log4net; namespace TestProject.Utils.Jsons { public class NullStringConverter : JsonConverter { private ILog _log =

Appending to JSON object using JSON.net

亡梦爱人 提交于 2019-12-25 03:52:45
问题 I need to serialize a JSON object that looks like this: { "Documents": [ { "Title": "", "DatePublished": "", "DocumentURL": "", "ThumbnailURL": "", "Abstract": "", "Sector": "", "Country": [ "", "", "" ], "Document Type": "" } ] } What I'm doing is taking the data from SQL server and storing the results into an object like this: public List<Dictionary<string, string>> GetResults() { int index = 0; while (this.myReader.Read()) { this.dataFrmDb = new Dictionary<string, string>(); for (int i = 0