How to parse JSON without JSON.NET library?
You can use the classes found in the System.Json Namespace which were added in .NET 4.5. You need to add a reference to the System.Runtime.Serialization assembly
The JsonValue.Parse() Method parses JSON text and returns a JsonValue:
JsonValue value = JsonValue.Parse(@"{ ""name"":""Prince Charming"", ...");
If you pass a string with a JSON object, you should be able to cast the value to a JsonObject:
using System.Json;
JsonObject result = value as JsonObject;
Console.WriteLine("Name .... {0}", (string)result["name"]);
Console.WriteLine("Artist .. {0}", (string)result["artist"]);
Console.WriteLine("Genre ... {0}", (string)result["genre"]);
Console.WriteLine("Album ... {0}", (string)result["album"]);
The classes are quite similar to those found in the System.Xml.Linq Namespace.
How to convert object to JSON without JSON.NET library?
If you want to serialize class into Json you can try this one too:
Install JSON.NET if you haven't yet.
make sure to include using Newtonsoft.Json;
and you can try this code:
Student s = new Student();
string json = JsonConvert.SerializeObject(s);
sorry for my bad english.
Parse JSON array without json.net
According to your json it actually represents one single Mod
object. That said, the json serializer should be parsing/deserializing a Mod
object instead of a list of Mod
objects, you should reflect that object structure in your serialisation code as follows...
var mod = new JavaScriptSerializer().Deserialize<Mod>(json);
foreach (button b in mod.buttons)
{
btnName.Add(b.name);
btnText.Add(b.text);
}
C# ASP.NET Parse JSON into Dataset without JSON.NET
I think your situation is the next, what you are trying to deserialize is not a dictionary, is an array/list, to solve this you can create a class with those two properties:
public class MyClass
{
public string Task { get; set; }
public string Staff { get; set; }
}
and later you can use it to deserialize youy JSON like this:
List<MyClass> parsedObj = JSS.Deserialize<List<MyClass>>(rawJSON);
Related Topics
What Operations Are Atomic in C#
Generics and Casting - Cannot Cast Inherited Class to Base Class
Optimal Linq Query to Get a Random Sub Collection - Shuffle
Changing the User Agent of the Webbrowser Control
Dot Character '.' in MVC Web API 2 for Request Such as API/People/Staff.45287
A Generic List of Anonymous Class
How to Drag and Drop Files into an Application
Displayname Attribute from Resources
What's the Difference Between Sortedlist and Sorteddictionary
Multiple Cases in Switch Statement
Shouldserialize*() VS *Specified Conditional Serialization Pattern
How to Calculate Float Type Precision and Does It Make Sense
When to Dispose Cancellationtokensource
Parsing Large JSON File in .Net
Is There a Generic Constructor with Parameter Constraint in C#