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 change property names when serializing with Json.net?

I have some data in a C# DataSet object. I can serialize it right now using a Json.net converter like this DataSet data = new DataSet(); // do some work here to populate ‘data’ string output = JsonConvert.SerializeObject(data); However, this uses the property names from data when printing to the .json file. I would like … 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

JSON.NET Error Self referencing loop detected for type

I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used JsonConvert.SerializeObject I got the following error: Error Self referencing loop detected for type System.data.entity occurs. How do I solve this problem? 26 s 26 That was the best solution https://docs.microsoft.com/en-us/archive/blogs/hongyes/loop-reference-handling-in-web-api Fix 1: Ignoring circular reference globally … Read more

How to ignore a property in class if null, using json.net

I am using Json.NET to serialize a class to JSON. I have the class like this: class Test1 { [JsonProperty(“id”)] public string ID { get; set; } [JsonProperty(“label”)] public string Label { get; set; } [JsonProperty(“url”)] public string URL { get; set; } [JsonProperty(“item”)] public List<Test2> Test2List { get; set; } } I want to … Read more

How can I deserialize JSON to a simple Dictionary in ASP.NET?

I have a simple key/value list in JSON being sent back to ASP.NET via POST. Example: { “key1”: “value1”, “key2”: “value2”} I AM NOT TRYING TO DESERIALIZE INTO STRONGLY-TYPED .NET OBJECTS I simply need a plain old Dictionary(Of String, String), or some equivalent (hash table, Dictionary(Of String, Object), old-school StringDictionary–hell, a 2-D array of strings … Read more