ReadJson() public method

Reads the JSON representation of the object.
public ReadJson ( JsonReader reader, Type objectType, JsonSerializer serializer ) : object
reader JsonReader The to read from.
objectType System.Type Type of the object.
serializer JsonSerializer The calling serializer.
return object
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonInterpreter"/> class.
        /// </summary>
        /// <param name="source">The <see cref="IResource"/>.</param>
        public JsonInterpreter(IResource source) : base(source)
        {
            string xmlContents = string.Empty;
            using(source)
            {
                JsonReader reader = new JsonTextReader(new StreamReader(source.Stream));
                reader.Read();

                XmlNodeConverter toXml = new XmlNodeConverter();
                XmlDocument xmlDoc = (XmlDocument)toXml.ReadJson(reader, typeof(XmlDocument));
                xmlContents = xmlDoc.OuterXml;
                reader.Close();                
            }

            IResource resource = new StaticContentResource(xmlContents);

            xmlInterpreter = new XmlConfigurationInterpreter(resource);
        }
    private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
    {
      JsonTextReader reader;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XmlNodeConverter converter = new XmlNodeConverter();
      if (deserializeRootElementName != null)
        converter.DeserializeRootElementName = deserializeRootElementName;

      XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());

#if !NET20
     string xmlText = node.OuterXml;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());

      string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
      if (d.Declaration != null)
        linqXmlText = d.Declaration + linqXmlText;

      Assert.AreEqual(xmlText, linqXmlText);
#endif

      return node;
    }