deserialization

JSON Deserializing for Windows Phone

隐身守侯 提交于 2019-12-20 06:23:57
问题 I am trying to deserialize the following JSON, but I really have no idea how to use JSON.net to do the work. I am using C# and JSON.Net library. My JSON is as follows: { "found": 3, "bounds": [ [ -43.54919, 172.62148 ], [ -43.54487, 172.63654 ] ], "features": [ { "id": 15342454, "centroid": { "type": "POINT", "coordinates": [ -43.54779, 172.62148 ] }, "bounds": [ [ -43.54779, 172.62148 ], [ -43.54779, 172.62148 ] ], "properties": { "osm_element": "node", "amenity": "toilets", "synthesized

Deserializing multiple objects from a single file [duplicate]

感情迁移 提交于 2019-12-20 06:09:20
问题 This question already has answers here : Deserialize multiple Java Objects (3 answers) Closed 5 years ago . I have a number of objects (of the same class) serialized into a file. But while deserializing it, only the first serialized object is deserialized. Code for serializing: public void save() { File f = new File("vehicule.txt"); try { if(!f.exists()) f.createNewFile(); } catch(IOException e) { } try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f,true)); oos

Is ISerializable backwards-compatible with previous versions of classes with fewer fields?

血红的双手。 提交于 2019-12-20 06:04:26
问题 Sorry if I've worded the question a bit odd! Basically, I have a serializable class that has a single field at this current time, but will definitely gain more in the future as we add features to the system. The serialization process will be used for both passing instances to a WCF service, and for reading/writing it from/to file. Of course, the latter may be a big problem if I'm continually updating the class with extra fields. Luckily, I think I've solved the problem by adding a try/catch

Combox SelectedItem does not apply when restoring from serialized ViewModel

二次信任 提交于 2019-12-20 06:03:07
问题 I'm facing a strange problem when using C# WPF and MVVM Pattern while restoring a ViewModel (serialized using Json.Net). The idea of the software is - when closing the window - to persist the current Viewmodel state in a json file. At the next startup the app just serarches for the json. If there a file, then deserialize it and restore the ViewModel (set public properties). If there is no file, then the viewmodel is created and default values are set. Now my problem is, that when restoring it

C# XML Serialization/Deserialization

余生长醉 提交于 2019-12-20 05:28:53
问题 I am brand new to C#. I'm taking a class on it right now, and one of our class examples wont compile. Visual Studio 2010 gives me this error: There is an error in XML document (3, 2). How should I edit the XML file to make it work with the code? Thank you for your help! public class SerializeIn { public static void Main() { // Declarations. Person[] p = new Person[0]; string infile = "Persons.xml"; StreamReader sr = new StreamReader(infile); XmlSerializer xs = new XmlSerializer(p.GetType());

handling name space changes during deserialization of JSON String

徘徊边缘 提交于 2019-12-20 05:02:12
问题 I have 2 applications that are communicate amongst each other with the help of a redis Server, In my first application i am able to serialize and de serialize and object of the following type { "$type": "System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib], [OPCMessagingService.Resource, OPCMessagingService]], mscorlib", "71": { "$type": "OPCMessagingService.Resource, OPCMessagingService", "SiteID": 2, "ResourceID": 71, "ProcessOrder": "001000380873", "CurrentStatus": 0,

How to deserialize collection of interfaces when concrete classes contains other interfaces

ぃ、小莉子 提交于 2019-12-20 04:22:49
问题 I am currently facing the situation where I get a json file that I can't modify and I want the resulting deserialized class to be generic for design purpose. First here are my interfaces : public interface IJobModel { string ClientBaseURL { get; set; } string UserEmail { get; set; } ExportType Type { get; set; } List<IItemModel> Items { get; set; } } public interface IItemModel { string Id { get; set; } string ImageSize { get; set; } string ImagePpi { get; set; } List<ICamSettings>

JSON.NET deserialize JSON object stored as property

雨燕双飞 提交于 2019-12-20 04:15:11
问题 I have a JSON message to deserialize with a string property containing the JSON of another object. I have the following classes public class Envelope { public string Type { get; set; } public Message InnerMessage { get; set; } } public class Message { public string From { get; set; } public string To { get; set; } public string Body { get; set; } } the JSON message I receive is in this format: { Type : "send", InnerMessage : "{ From: \"sender\", To: \"receiver\", Body: \"test\" }" } note that

Json.NET Uri (de)serialization errors

空扰寡人 提交于 2019-12-20 02:47:06
问题 I need to serialize and deserialize an object that contains an System.Uri property using the latest (4.0.3) Json.NET library. The following code demonstrates the problem: string input = "http://test.com/%22foo+bar%22"; Uri uri = new Uri(input); string json = JsonConvert.SerializeObject(uri); Uri output = JsonConvert.DeserializeObject<Uri>(json); The DeserializeObject method throws an JsonReaderException. This works fine with 4.0.2. I've submitted an issue on codeplex with tests and patch to

Java partial (de)serialization of objects

爱⌒轻易说出口 提交于 2019-12-20 02:35:35
问题 Let's say we have 3 Classes: class foo { // not a singleton String s; } class bar { foo f; int i; } class baz { foo sameF; } Now we create instances foo onlyFoo = new foo("the only one"); bar theBar = new bar(onlyFoo, 123); baz theBaz = new baz(onlyFoo); After that we want to store them serilazed in a file. If we deserialze theBaz, modify onlyFoo and deserialize theBaz to the file again, theBar still contains the original onlyFoo, so there are two different versions of onlyFoo. What I want