Converting Stream to String and back

I have just tested this and works fine. string test = “Testing 1-2-3”; // convert string to stream byte[] byteArray = Encoding.ASCII.GetBytes(test); MemoryStream stream = new MemoryStream(byteArray); // convert stream to string StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); If stream has already been written to, you might want to seek to the … Read more

.NET NewtonSoft JSON deserialize map to a different property name

Json.NET – Newtonsoft has a JsonPropertyAttribute which allows you to specify the name of a JSON property, so your code should be: public class TeamScore { [JsonProperty(“eighty_min_score”)] public string EightyMinScore { get; set; } [JsonProperty(“home_or_away”)] public string HomeOrAway { get; set; } [JsonProperty(“score “)] public string Score { get; set; } [JsonProperty(“team_id”)] public string TeamId … Read more

Performant Entity Serialization: BSON vs MessagePack (vs JSON)

// Please note that I’m author of MessagePack. This answer may be biased. Format design Compatibility with JSON In spite of its name, BSON’s compatibility with JSON is not so good compared with MessagePack. BSON has special types like “ObjectId”, “Min key”, “UUID” or “MD5” (I think these types are required by MongoDB). These types … Read more

Converting Stream to String and back…what are we missing?

I have just tested this and works fine. string test = “Testing 1-2-3”; // convert string to stream byte[] byteArray = Encoding.ASCII.GetBytes(test); MemoryStream stream = new MemoryStream(byteArray); // convert stream to string StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); If stream has already been written to, you might want to seek to the … Read more

What is deserialize and serialize in JSON?

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object). When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom in this format. Serialization … Read more

Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

You can use the C# dynamic type to make things easier. This technique also makes re-factoring simpler as it does not rely on magic-strings. JSON The JSON string below is a simple response from an HTTP API call, and it defines two properties: Id and Name. {“Id”: 1, “Name”: “biofractal”} C# Use JsonConvert.DeserializeObject<dynamic>() to deserialize … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)