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

I want to serialize objects to strings, and back. We use protobuf-net to turn an object into a Stream and back, successfully. However, Stream to string and back… not so successful. After going through StreamToString and StringToStream, the new Streamisn’t deserialized by protobuf-net; it raises an Arithmetic Operation resulted in an Overflow exception. If we … Read more

Deserializing a JSON into a JavaScript object

I have a string in a Java server application that is accessed using AJAX. It looks something like the following: var json = [{ “adjacencies”: [ { “nodeTo”: “graphnode2”, “nodeFrom”: “graphnode1”, “data”: { “$color”: “#557EAA” } } ], “data”: { “$color”: “#EBB056”, “$type”: “triangle”, “$dim”: 9 }, “id”: “graphnode1”, “name”: “graphnode1” },{ “adjacencies”: [], “data”: … Read more

How to implement custom JsonConverter in JSON.NET?

I am trying to extend the JSON.net example given here http://james.newtonking.com/projects/json/help/CustomCreationConverter.html I have another sub class deriving from base class/Interface public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public class Employee : Person { public string Department { get; set; } public string JobTitle … Read more

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

I know there are a few posts about Newtonsoft so hopefully this isn’t exactly a repeat…I’m trying to convert JSON data returned by Kazaa’s API into a nice object of some kind WebClient client = new WebClient(); Stream stream = client.OpenRead(“http://api.kazaa.com/api/v1/search.json?q=muse&type=Album”); StreamReader reader = new StreamReader(stream); List<string> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(reader.Read().ToString()); foreach (string item in list) … Read more

.NET NewtonSoft JSON deserialize map to a different property name

I have following JSON string which is received from an external party. { “team”:[ { “v1″:””, “attributes”:{ “eighty_min_score”:””, “home_or_away”:”home”, “score”:”22″, “team_id”:”500″ } }, { “v1″:””, “attributes”:{ “eighty_min_score”:””, “home_or_away”:”away”, “score”:”30″, “team_id”:”600″ } } ] } My mapping classes: public class Attributes { public string eighty_min_score { get; set; } public string home_or_away { get; set; } … Read more

How can I parse JSON with C#?

I have the following code: var user = (Dictionary<string, object>)serializer.DeserializeObject(responsecontent); The input in responsecontent is JSON, but it is not properly parsed into an object. How should I properly deserialize it? 17 s 17 As was answered here – Deserialize JSON into C# dynamic object? It’s pretty simple using Json.NET: dynamic stuff = JsonConvert.DeserializeObject(“{ ‘Name’: … Read more