deserialization

Rename Property from Deserialized Javascript

南楼画角 提交于 2019-12-13 03:43:23
问题 How do I take deserialize JavaScript and change the name of the property being processed? For example: class MyClass { public string CreateDate {get;set;} } public class DeserializeMyClass { //How do I take "create_date" and convert it to CreateDate? Is there an attribute I //can use? var json = @"{""create_date"":""04/12/2013""}"; var ds = new JavaScriptSerializer(); ds.Deserialize<MyClass>(json); } Thanks in advance! 回答1: Looks like you can't do it easily for JavaScriptSerializer, but you

C# - Unexpected character encountered while parsing value: {. Path '[0].Statistics

廉价感情. 提交于 2019-12-13 03:22:55
问题 I am trying to deserialize a JSON object according to my model using the code below: LoadData<MyModel>(Data.Stats, null); public void LoadData<TModel>(string data, JsonSerializerSettings jsonSettings) where TModel : class { var mockData = JsonConvert.DeserializeObject<Collection<TModel>>(data, jsonSettings); // ERROR HERE Context.SaveChanges(); } However I am getting an error that reads Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: {. Path '[0]

Scala Object with ArrayBuffer - Deserialize issue using Gson

坚强是说给别人听的谎言 提交于 2019-12-13 03:09:20
问题 I have a top level scala class something like below: FinalOutput.scala: class FinalOutput extends Serializable { @BeanProperty var userId: String = _ @BeanProperty var tenantId: String = _ @BeanProperty @SerializedName("type") var dataType: String = _ @BeanProperty var data: FinalData = _ @BeanProperty var userCreatedDate: String = _ } FinalData.scala : class FinalData extends Serializable { @BeanProperty var list1: ArrayBuffer[DataType1] = _ @BeanProperty var list2: ArrayBuffer[DataType2] =

How to ignore data in JSON.NET that changes between returns

ⅰ亾dé卋堺 提交于 2019-12-13 03:04:52
问题 I'm parsing JSON data return by a third party. I have my class generated with JSON2CSharp which works for the first sample we received. I tweaked it to have some JsonProperty settings so that it doesn't require certain properties that are not always present. Now I received more samples and one of the datablobs changed format from needing public Translations Translations { get; set; } to public List<Translations> Translations { get; set; } The blob however is information we do not need, for

Dynamic Schema & Deserialization with Protostuff

不打扰是莪最后的温柔 提交于 2019-12-13 02:01:44
问题 I'm using Protostuff in an attempt to serialize/deserialize objects of several different types for which no protobuf sources are available (it's a server-server RPC scenario). Serialization goes OK because I know the type of the object to serialize and can create the schema: Schema schema = RuntimeSchema.getSchema(object.getClass()); Now, I use ProtobufIOUtil.toByteArray and get a byte array which I then pass to a remote server. However, I can't seem to deserialize this byte array in the

Deserializing a string property value to a class instance using JSON.Net

隐身守侯 提交于 2019-12-13 01:47:28
问题 I'm deserializing some JSON from a server which is, for the most part, simple: { "id": "ABC123" "number" 1234, "configured_perspective": "ComplexPerspective[WithOptions,Encoded]" } That "configured_perspective" property, however, is an unfortunate case of the server using a weirdly put-together string when a nested object would have been better. To ease the suffering of our .NET users, I convert this into a custom class in my object model: public class Example { public string id { get; set; }

RestSharp Deserialization of empty string to Dictionary Error

那年仲夏 提交于 2019-12-13 01:34:46
问题 I'm a bit new to RestSharp so please excuse my ignorance. I'm getting the following error: {"Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'."} This happens when RestSharp tries to deserialize and empty string to a Dictionary object. Here is the my abbreviated Result object: public class Result { public Dictionary<string, string> assignment_group { get; set; } } Here is what is returned if assignment_group is

Deserialize flatbuffers binary that represents non-root table

天涯浪子 提交于 2019-12-13 01:33:25
问题 Is it possible to deserialize a binary flatbuffers object that represents a non-root table? Suppose the following flatbuffers schema: table Foo { ... } table Bar { value:[Foo]; } root_type Bar; Suppose we have access to the binary data that represents the Foo object. Is it possible to deserialize this binary to an object of class Foo ? Looking at my c++ generated header file, I do not see any generated function like GetFoo() . 回答1: GetFoo is just a convenience function for the declared root

SerializationException was unhandled: The input stream is not a valid binary format. The starting contents (in bytes) are

限于喜欢 提交于 2019-12-13 01:12:52
问题 really stuck, any help and/or comments would be greatly appreciated! I've written a database program that needs to be able to load contents from a file into a list. So basically i'm trying to use serialization and deserialization for this. The area where the error occurs is in bold and is italicized: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary;

Type.GetType returns Nothing in SerializationBinder

ぃ、小莉子 提交于 2019-12-13 00:44:17
问题 I am creating a vb.net application which needs to be able to deserialize files that were serialized in a different application as well as serialize files that can be deserialized in that other application. I am trying to make this work via the use of a SerializationBinder to convert the type during serialize / deserialize. Using This article from MSDN as a reference, this is what I have at this point.... In my deserialize function: myDeserializer.Binder = New TypeConverter() openCount =