Silverlight in the Json data conversion methods (English)

2010-08-04  来源:本站原创  分类:DotNet  人气:166 

[DataContract]
    public class User
    {
        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public int Age { get; set; }

        public User() { }

        public User(string newName, int newAge)
        {
            Name = newName;
            Age = newAge;
        }

    }
// Into Json data
        public static string WriteFromObject()
        {
            User user = new User("Bob", 42);
            MemoryStream ms = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));
            ser.WriteObject(ms, user);
            byte[] json = ms.ToArray();
            ms.Close();
            return Encoding.UTF8.GetString(json, 0, json.Length);
        }

        //Json Into class
        public static User ReadToObject(string json)
        {
            User deserializedUser = new User();
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
            DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType());
            deserializedUser = ser.ReadObject(ms) as User;
            ms.Close();
            return deserializedUser;
        }
相关文章
  • Silverlight in the Json data conversion methods (English) 2010-08-04

    [DataContract] public class User { [DataMember] public string Name { get; set; } [DataMember] public int Age { get; set; } public User() { } public User(string newName, int newAge) { Name = newName; Age = newAge; } } // Into Json data public static s

  • Silverlight in the Json data conversion method (in Chinese) 2010-08-04

    [DataContract] public class User { [DataMember] public string Name { get; set; } [DataMember] public int Age { get; set; } public User() { } public User(string newName, int newAge) { Name = newName; Age = newAge; } } // Into Json data public static s

  • Json data conversion method 2010-07-06

    <script type="text/javascript" src="json2.js"> </ script> <script> / / Json data structure directly Statement var myJSONObject = ("bindings": [ ("IrcEvent": "PRIVMSG", "method":

  • JSON data conversion and JAVA 2010-07-03

    Keywords: json java JSON-lib the Java class package for the bean, map and converted into JSON and XML to JSON back into the bean and DynaBean. Download: http://json-lib.sourceforge.net/ Still need 3rd party packages: org.apache.commons (3.2 or later)

  • [Reprinted] json data exchange with Java 2010-08-22

    JSON data conversion and JAVA Keywords: json java JSON-lib the Java class package for the bean, map and converted into JSON and XML to JSON back into the bean and DynaBean. Download: http://json-lib.sourceforge.net/ Still need 3rd party packages: org

  • Simple JSON data format conversion classes 2010-03-29

    In the project to transfer data using the JSON format, often encounter data format conversion, generally you can use the Json.org's lib, as well as some third-party framework to complete. But if it is a simple project, and the use of json is not much

  • json data and data conversion JAVA 2010-07-13

    Transfer from: http://zhkac.javaeye.com/blog/505218 1, DTO: Data Transfer Object, Data Transfer Object 2, the date format problem, has also been dealing with 3, json-lib-2.2.2-jdk13.jar (2.1 in the date array of json-> java problem) Tools JsonUtil co

  • Read JSON data in Silverlight 2010-12-02

    Assumed in accordance with the How to: HTTP-based service approach is described in a request to the HTTP-based Web service request, the type in the Stream responseStream object returns the following JSON. {"IsMember": true, "Name": &qu

  • Json on the date type of data conversion 2010-08-19

    See the forum has a solution, make a memorandum of their own json data types inside "Coltime": ("month": 09, "day": 20, "year": 106, "nanos": 1, "time": 231223232, "seconds": 25, "

  • For Lotus Domino databases and relational database data conversion relationship between study 2011-04-21

    I contributed articles to the developerWorks article, written in general, included in this: http://www.ibm.com/developerworks/cn/lotus/domino-orm/ Introduction Domino databases and relational database is the circulation of data between the Domino use

  • For Lotus Domino databases and relational database data conversion between the study of the relationship 2011-04-21

    I contributed articles to the developerWorks article, written in general, included in this: http://www.ibm.com/developerworks/cn/lotus/domino-orm/ Introduction Domino databases and relational databases is the flow of data between the Domino users fac

  • Android on the interactive applications based on JSON data 2010-03-29

    JSON definition: A lightweight data interchange format, has a good quick read and easy to prepare features. The mainstream technology industry to provide a complete solution (somewhat similar to the regular expression, access to the majority of today

  • Java project development in different types of data conversion 2010-04-08

    In the Java project development process, create some common methods to achieve different types of data conversion, summarized as follows: / ** * Character into integer * @ Param source * @ Return * / public static int strtoint (String source) ( int n

  • PHP and AJAX call to return json data 2010-05-26

    When using ajax to return multiple values, they can use xml, can use json json examples <html> <head> <title> AjaxTest </ title> <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest () ( if (wi

  • jQuery call WebService return JSON data 2010-05-30

    jQuery call WebService return JSON data JQuery 2009-12-23 17:18:49 Read 73 Comments 0 font size: large, medium jQuery call WebService online presentation is also more recent project, I also used a lot, has not happen often. NET Ajax, jQuery call to r

  • Actionscript inside of the band, and data conversion 2010-07-01

    Transfer from: http://www.xiiid.com/blog/article.asp?id=166 Ary and data conversion has been a headache for the novice who, together with the AS's not familiar with, they would often do things that make a fuss. Sometimes mention hex conversion (such

  • Large amount of data, large data processing Methods (zz) 2010-10-09

    Since: http://hi.baidu.com/secondbysecond/blog/item/de06890e9a0fae276159f334.html Large amount of data, large data processing Methods (zz) Large data problem is a lot of interview questions that often appear in written test, such as Tencent baidu goo

  • generation jQuery and struts2 json data returned 2010-11-29

    The introduction of package (This article is cited in the package all the struts-2.1.8.1 \ lib): struts2-json-plugin-2.1.8.1.jar json-lib-2.1.jar commons-collections-3.2.jar commons-beanutils-1.7.0.jar commons-lang-2.3.jar commons-logging-1.0.4.jar e

  • background java jquery json data analysis 2011-05-29

    1, the initial contact with jquery and json, hope a little help Foreground application to the background to get json data ajax $.ajax({ type: "POST", url: "ResourseAction!showTables.action", data:"", success: function(jsonDat

  • Large amount of data, summary of massive data processing methods (transfer) 2011-08-16

    Large amount of data, summary of massive data processing methods (transfer) Large amount of data is often written a lot of interview problems, such as baidu google Tencent such massive amounts of data related to some of the companies are often asked.