jsonserializer

Preventing StackOverflowException while serializing Entity Framework object graph into Json

两盒软妹~` 提交于 2019-11-27 21:42:11
I want to serialize an Entity Framework Self-Tracking Entities full object graph (parent + children in one to many relationships) into Json. For serializing I use ServiceStack.JsonSerializer . This is how my database looks like (for simplicity, I dropped all irrelevant fields): I fetch a full profile graph in this way: public Profile GetUserProfile(Guid userID) { using (var db = new AcmeEntities()) { return db.Profiles.Include("ProfileImages").Single(p => p.UserId == userId); } } The problem is that attempting to serialize it: Profile profile = GetUserProfile(userId); ServiceStack

Grails - grails.converters.JSON - removing the class name

£可爱£侵袭症+ 提交于 2019-11-27 16:11:50
问题 Is there a way to remove the class field in a JSON converter? Example: import testproject.* import grails.converters.* emp = new Employee() emp.lastName = "Bar" emp as JSON as a string is {"class":"testproject.Employee","id":null,"lastName":"Bar"} I'd prefer {"id":null,"lastName":"Bar"} Is there a way to add one more line of code at the end to remove the class field? 回答1: Here is yet one way to do it. I've added a next code to the domain class: static { grails.converters.JSON

Cannot find JavaScriptSerializer in .Net 4.0

只谈情不闲聊 提交于 2019-11-27 05:57:54
I cannot seem to find the JavaScriptSerializer object nor the the System.Web.Script.Serialization namespace within Visual Studio 2010. I need to serialize something to JSON what am I supposed to use? And yes, I already included the System.Web.Extensions (in System.Web.Extensions.dll) within the project. Which is why I am shocked? I do know System.Web.Extensions was marked as obsolete in 3.5 Steffen Check if you included the .net 4 version of System.Web.Extensions - there's a 3.5 version as well, but I don't think that one works. These steps work for me: Create a new console application Change

JsonSerializer - serialize decimal places with 'N2' formatting

∥☆過路亽.° 提交于 2019-11-27 02:43:44
问题 I'm serializing decimals using Newtonsoft.Json.JsonSerializer. How can I set it to serialize decimal numbers with only 1 decimal place to use 0 at the end. i.e. 3.5 serializes to "3.50"? 回答1: You'll have to write your own custom JsonConverter and use it to intercept the decimal type so you can change how it gets serialized. Here's an example: public class DecimalFormatConverter : JsonConverter { public override bool CanConvert(Type objectType) { return (objectType == typeof(decimal)); }

Does .NET 4 have a built-in JSON serializer/deserializer?

限于喜欢 提交于 2019-11-26 22:07:36
Does .NET 4 come with any class that serializes/deserializes JSON data? I know there are 3rd-party libraries, such as JSON.NET , but I am looking for something built right into .NET. I found Data Contracts on MSDN, but it is for WCF, not for Winforms or WPF. You can use the DataContractJsonSerializer class anywhere you want, it is just a .net class and is not limited to WCF. More info on how to use it here and here . There's the JavaScriptSerializer class (although you will need to reference the System.Web.Extensions assembly the class works perfectly fine in WinForms/WPF applications). Also

Ruby objects and JSON serialization (without Rails)

你。 提交于 2019-11-26 21:34:56
I'm trying to understand the JSON serialization landscape in Ruby. I'm new to Ruby. Is there any good JSON serialization options if you are not working with Rails? That seems to be where this answer goes (to Rails) How to convert a Ruby object to JSON The json gem seems to make it look like you have to write your own to_json method. I haven't been able to get to_json to work with arrays and hashes (documentation says it works with these) Is there a reason the json gem doesn't just reflect over the object and use a default serialization strategy? Isn't this how to_yaml works (guessing here) For

Preventing StackOverflowException while serializing Entity Framework object graph into Json

守給你的承諾、 提交于 2019-11-26 20:46:25
问题 I want to serialize an Entity Framework Self-Tracking Entities full object graph (parent + children in one to many relationships) into Json. For serializing I use ServiceStack.JsonSerializer . This is how my database looks like (for simplicity, I dropped all irrelevant fields): I fetch a full profile graph in this way: public Profile GetUserProfile(Guid userID) { using (var db = new AcmeEntities()) { return db.Profiles.Include("ProfileImages").Single(p => p.UserId == userId); } } The problem

Cannot find JavaScriptSerializer in .Net 4.0

大城市里の小女人 提交于 2019-11-26 11:48:13
问题 I cannot seem to find the JavaScriptSerializer object nor the the System.Web.Script.Serialization namespace within Visual Studio 2010. I need to serialize something to JSON what am I supposed to use? And yes, I already included the System.Web.Extensions (in System.Web.Extensions.dll) within the project. Which is why I am shocked? I do know System.Web.Extensions was marked as obsolete in 3.5 回答1: Check if you included the .net 4 version of System.Web.Extensions - there's a 3.5 version as well,

Does .NET 4 have a built-in JSON serializer/deserializer?

江枫思渺然 提交于 2019-11-26 08:10:10
问题 Does .NET 4 come with any class that serializes/deserializes JSON data? I know there are 3rd-party libraries, such as JSON.NET, but I am looking for something built right into .NET. I found Data Contracts on MSDN, but it is for WCF, not for Winforms or WPF. 回答1: You can use the DataContractJsonSerializer class anywhere you want, it is just a .net class and is not limited to WCF. More info on how to use it here and here. 回答2: There's the JavaScriptSerializer class (although you will need to

Ruby objects and JSON serialization (without Rails)

久未见 提交于 2019-11-26 07:23:35
问题 I\'m trying to understand the JSON serialization landscape in Ruby. I\'m new to Ruby. Is there any good JSON serialization options if you are not working with Rails? That seems to be where this answer goes (to Rails) How to convert a Ruby object to JSON The json gem seems to make it look like you have to write your own to_json method. I haven\'t been able to get to_json to work with arrays and hashes (documentation says it works with these) Is there a reason the json gem doesn\'t just reflect