Serialization and deserialization problems in front and back of JSON

1. Deserialize in js

First look at a string in JSON format:

var  xiaoming = "{
  "name": "小明",
  "age": 14,
  "gender": true,
  "height": 1.65,
  "grade": null,
  "middle-school": "\"W3C\" Middle School",
  "skills": [
    "JavaScript",
    "Java",
    "Python",
    "Lisp"
  ]
}"

To deserialize this string into an object in js:

JSON.parse(xiaoming);

2. Serialization in js

Object

var xiaoming = {
    name: '小明',
    age: 14,
    gender: true,
    height: 1.65,
    grade: null,
    'middle-school': '\"W3C\" Middle School',
    skills: ['JavaScript', 'Java', 'Python', 'Lisp']
};

To serialize this object to json string in js

JSON.stringify(xiaoming);

3. Use the Newtonsoft.Json tool to serialize and deserialize json in c #

   Import Newtonsoft.Json namespace

using Newtonsoft.Json;

 Serialize JsonConvert.SerializeObject (stu);

Deserialize JsonConvert.DeSerializeObject (str);

 

Guess you like

Origin www.cnblogs.com/alan-1996/p/12671911.html