C# (CSharp) Netduino.WebServer.Core.Json 네임스페이스

클래스들

이름 설명
JsonArray A Json Array. Programmed by Huysentruit Wouter See the Json.ToJson method for more information.
JsonObject A Json Object. Programmed by Huysentruit Wouter See the Json.ToJson method for more information.
JsonParser Parses JSON strings into a Hashtable. The Hashtable contains one or more key/value pairs (DictionaryEntry objects). Each key is the name of a property that (hopefully) exists in the class object that it represents. Each value is one of the following: Hastable - Another list of one or more DictionaryEntry objects, essentially representing a property that is another class. ArrayList - An array of one or more objects, which themselves can be one of the items enumerated in this list. Value Type - an actual value, such as a string, int, bool, Guid, DateTime, etc
JsonPrimitives
PropertyTable Contains a snapshot of all of the classes currently loaded by the Assembly and enumerates their class names, properties and property types into a Hashtable. The table is then referenced against a decoded Json string to determine what data types a given chunk of Json string represents. When a match is found, that class is instantiated and its properties populated with the Json data.
Serializer .NET Micro Framework JSON Serializer and Deserializer. Mimics, as closely as possible, the excellent JSON (de)serializer at http://www.json.org. You can (de)serialize just about any object that contains real property values: Value Types (int, bool, string, etc), Classes, Arrays, Dictionaries, Hashtables, etc. Caveats: 1) Each property to be (de)serialized must be public, and contain BOTH a property getter and setter. 2) You can't (de)serialize interfaces, virtual or abstract properties, private properties. Your class can contain these objects, but their values are not (de)serialized. 3) DateTime objects can be (de)serialized, and their format in JSON will be ISO 8601 format. 4) Guids can be (de)serialized. 3) You can't use Array or IList because they are abstract (or an interface). Use ArrayList instead. 4) You can't use IDictionaryEntry, use DictionaryEntry instead. 5) .NET MF floating point seems to have very little precision, at least on my GHI USBizi hardware. I get only about 3 or 4 decimal places of accuracy. How does this class work, given the extremely limited Reflection capabilities? Serialization is easy: you take the specified object, enumerate its Methods (yes, Methods, there is no Property enumeration), and find the getters and setters, filtering out the unusable items. Then you just JSON-format the Property names and their values. Deserialization is much more difficult, as JSON contains no type definitions, and .NET MF contains next-to-zero assistance. We instantiate a PropertyTable class to enumerate every public class that's loaded by this process, and create a non-heirarchical Hashtable list of all public classes, their property names, and each Property's Type. When the JSON string is presented for deserialization, the JSON string is parsed (using this class) into a heirarchical Hashtable, containing all of the properties and their values. At that point, you have (a) a Hastable containing Property Names with their Types, and (b) a Hastable containing the Property Names and their actual Values. Deserialization at that point is a matter of matching the Properties in the two lists, instantiating them by their Type, and setting their Values. Hoping of course that you contain no classes with identical property names. This is more difficult than it sounds. In normal .NET, you have boxing/unboxing to convert any object to any defined Type. In .NET MF, you do not. The only Type that an object will unbox into is the type exposed by the ReturnType property of the Parse method on the object. So a LOT of wrangling is needed to properly unbox types from JSON into C#. But it (mostly) works.