datacontractjsonserializer

Serialize Dictionary<TKey, TValue> to JSON with DataContractJsonSerializer

做~自己de王妃 提交于 2019-11-30 17:29:05
I have an object tree that I'm serializing to JSON with DataContractJsonSerializer . Dictionary<TKey, TValue> gets serialized but I don't like the markup - the items are not rendered like this: {key1:value, key2:value2} but rather like an array of serialized KeyValuePair<TKey, TValue> objects: [{ "__type":"KeyValuePairOfstringanyType:#System.Collections.Generic", "key":"key1", "value":"value1" }, { "__type":"KeyValuePairOfstringanyType:#System.Collections.Generic", "key":"key2", "value":"value2" }] Ugly, isn't it? So, I avoid this by wrapping the generic Dictionary in a custom object that

Safest place for the XmlSerializer to save temp files

China☆狼群 提交于 2019-11-30 17:25:18
问题 It's come to my attention that the XmlSerializer needs to use disk space to do its bidding. If there is no writeable %temp% folder, then it fails with an error as follows: Source : System.Xml Message : Unable to generate a temporary class (result=1). error CS2001: Source file 'C:\Windows\TEMP\c1ls4elp.0.cs' could not be found error CS2008: No inputs specified StackTrace : at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters,

How to deserialize JSON with unnamed collection of types using DataContractSerializer

心已入冬 提交于 2019-11-30 09:22:07
问题 I'm using web service to get data about route mileage. Then I'm using deserializer to parse it out. Here is how JSON looks: [{"__type":"CalculateMilesReport:http:\/\/pcmiler.alk.com\/APIs\/v1.0","RouteID":null,"TMiles":445.5] With this response I had couple issues. Why is is wrapped into collection and how do I set object model? Also it was complaining about special __type attribute. So, I did "hack" and "prepped" string: // Cut off first and last charachters [] - they send objects as arrays

Way to Deserialize JSON from HttpWebResponse without 3rd party frameworks

青春壹個敷衍的年華 提交于 2019-11-29 05:18:31
I'm trying to keep from depending on open source or third party libraries such as Json.NET to parse incoming JSON from an HttpWebResponse. Why? Because the more reliance on open source frameworks to aid in your implementations, the more your app has to rely on those dependencies...I don't like my apps to be depenent on a lot of libraries for many reasons if at all possible. I'm ok with using stuff like Enterprise Library because it's supported by MS but I'm taking more open source libraries. Anyway, I'm trying to figure out the best way to parse incoming JSON server-side in .NET 3.5. I know

Way to Deserialize JSON from HttpWebResponse without 3rd party frameworks

ぃ、小莉子 提交于 2019-11-27 19:03:57
问题 I'm trying to keep from depending on open source or third party libraries such as Json.NET to parse incoming JSON from an HttpWebResponse. Why? Because the more reliance on open source frameworks to aid in your implementations, the more your app has to rely on those dependencies...I don't like my apps to be depenent on a lot of libraries for many reasons if at all possible. I'm ok with using stuff like Enterprise Library because it's supported by MS but I'm taking more open source libraries.

DataContractJsonSerializer - Deserializing DateTime within List<object>

被刻印的时光 ゝ 提交于 2019-11-27 08:45:47
I'm having trouble using the System.Runtime.Serialization.Json.DataContractJsonSerializer class to deserialize DateTime instances contained within a List<object> . I cannot seem to get DateTime to deserialize back into the original type. The DataContractJsonSerializer always deserializes it into a string type with the format "/Date(1329159196126-0500)/" . It'll serialize and deserialize fine if I run it through using a strongly typed List<DateTime> , however I am looking for way to get the serializer to identify and properly deserialize DateTimes when encountered within a simple list or array

DataContractJsonSerializer - Deserializing DateTime within List<object>

橙三吉。 提交于 2019-11-26 14:17:54
问题 I'm having trouble using the System.Runtime.Serialization.Json.DataContractJsonSerializer class to deserialize DateTime instances contained within a List<object> . I cannot seem to get DateTime to deserialize back into the original type. The DataContractJsonSerializer always deserializes it into a string type with the format "/Date(1329159196126-0500)/" . It'll serialize and deserialize fine if I run it through using a strongly typed List<DateTime> , however I am looking for way to get the