jsonserializer

Cannot find DataContractJsonSerializer from an Asp.Net Mvc application

放肆的年华 提交于 2019-12-03 06:24:05
I can't get access to the DataContractJsonSerializer method from System.Runtime.Serialization.Json If I do: using System.Runtime.Serialization.Json; I get an error... How can I access this in my Asp.Net Mvc app so I can use the DataContractJsonSerializer method Make sure you've referenced the DLL where this type lives: System.ServiceModel.Web.dll Right Click in Project, Add Reference... Search for System.Runtime.Serialization Click Ok/Add 来源: https://stackoverflow.com/questions/1127264/cannot-find-datacontractjsonserializer-from-an-asp-net-mvc-application

How to pass parameter to JsonSerializer?

大城市里の小女人 提交于 2019-12-03 00:35:18
I have a simple data service : @GET public Data getData(@QueryParam("id") Long id) { Data data = dataService.getData(id); return data; } And a matching DataSerializer that implements JsonSerializer<Data> : The DataSerializer is registered to Jackson via : simpleModule.addSerializer(Data.class , dataSerializer); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(simpleModule); It works well. But today , I want to add another Locale parameter , and hope the DataSerializer to output correspondent content : @GET public Data getData(@QueryParam("id") Long id , @QueryParam("locale")

Web API: Failed to serialize the response body for content type

你。 提交于 2019-12-02 03:58:54
I am working with ASP.NET MVC 5 Web Api. I am having existing application with many api's. Recently I have implemented custom JsonConverter which will convert Date as per timezone. public class CustomInfoConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(CustomType); } public override bool CanRead { get { return false; } } public override bool CanWrite { get { return true; } } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var customType = (CustomType)value; if (customType == null || null==

How to do Conditional Serialization using C# - NewtonSoft.Json

穿精又带淫゛_ 提交于 2019-12-01 14:32:41
I am doing json serialization using NewtonSoft.Json public class CommonBase { [JsonProperty(PropertyName = "u_customer_id")] public long CustomerId { get; set; } } I want to do a conditional serialization so that if CustomerId value is 0, I want to set a blank value for CustomerId during json serialization. Since CommonBase is a base class and I am not able to change data type from long to string . How can I achieve this? You almost have the answer in your question title. What you are looking for is Conditional Property Serialization You just need to add method named like this: ShouldSerialize

how to map a JSON to a java model class

只谈情不闲聊 提交于 2019-12-01 13:17:19
I need to map JSON obj to a class and its arrays to ArrayList in Android and it should have all the children data as well. (with nested arraylists too) and i need to convert updated data list again to jsonobject my json string is { "type": "already_planted", "crops": [ { "crop_id": 1, "crop_name": "apple", "crop_details": [ { "created_id": "2017-01-17", "questions": [ { "plants": "10" }, { "planted_by": "A person" } ] }, { "created_id": "2017-01-30", "questions": [ { "plants": "15" }, { "planted_by": "B person" } ] } ] }, { "crop_id": 2, "crop_name": "Cashew", "crop_details": [ { "created_id":

how to map a JSON to a java model class

笑着哭i 提交于 2019-12-01 09:54:23
问题 I need to map JSON obj to a class and its arrays to ArrayList in Android and it should have all the children data as well. (with nested arraylists too) and i need to convert updated data list again to jsonobject my json string is { "type": "already_planted", "crops": [ { "crop_id": 1, "crop_name": "apple", "crop_details": [ { "created_id": "2017-01-17", "questions": [ { "plants": "10" }, { "planted_by": "A person" } ] }, { "created_id": "2017-01-30", "questions": [ { "plants": "15" }, {

Is there any way to JSON.NET-serialize a subclass of List<T> that also has extra properties?

只愿长相守 提交于 2019-11-29 06:26:56
Ok, we're using Newtonsoft's JSON.NET product, which I really love. However, I have a simple class structure for hierarchical locations that look roughly like this... public class Location { public string Name{ get; set; } public LocationList Locations{ get; set; } } // Note: LocationList is simply a subclass of a List<T> // which then adds an IsExpanded property for use by the UI. public class LocationList : List<Location> { public bool IsExpanded{ get; set; } } public class RootViewModel { public LocationList RootLocations{ get; set; } } ...and when I serialize them to JSON, it all works

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

谁都会走 提交于 2019-11-29 01:44:42
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? Here is yet one way to do it. I've added a next code to the domain class: static { grails.converters.JSON.registerObjectMarshaller(Employee) { return it.properties.findAll {k,v -> k != 'class'} } } But as I found if you have used

How to use Gson to serialize objects in android?

a 夏天 提交于 2019-11-28 12:29:15
I want to send 2 objects to Java server from Android client using socket (as I am developing a Remote PC). AndroidClient.java public class MainActivity extends Activity{ Socket client; ObjectOutputStream oos; OutputStream os; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SendObj so=new SendObj(); so.execute(); } class SendObj extends AsyncTask<Void, Void, Void>{ @Override protected Void doInBackground(Void... arg0) { try { client=new Socket("192.168.237.1",6566); os=client.getOutputStream(); oos=new

JObject.Parse vs JsonConvert.DeserializeObject

我只是一个虾纸丫 提交于 2019-11-28 04:36:58
What's the difference between JsonConvert.DeserializeObject and JObject.Parse? As far as I can tell, both take a string and are in the Json.NET library. What kind of situation would make one more convenient than the other, or is it mainly just preference? For reference, here's an example of me using both to do exactly the same thing - parse a Json string and return a list of one of the Json attributes. public ActionResult ReadJson() { string countiesJson = "{'Everything':[{'county_name':null,'description':null,'feat_class':'Civil','feature_id':'36865'," +"'fips_class':'H1','fips_county_cd':'1'