Home >Web Front-end >JS Tutorial >Example of javascript implementation of json serialization and deserialization functions

Example of javascript implementation of json serialization and deserialization functions

陈政宽~
陈政宽~Original
2017-06-28 12:47:561435browse

This article mainly introduces the serialization and deserialization functions of json implemented by JS, and analyzes the serialization and deserialization related implementation techniques for json based on specific examples. Friends who need it You can refer to the following The example of this article describes the JS implementation of json serialization and deserialization functions. Share it with everyone for your reference, the details are as follows:

Serialization:

var s = new Object();
s.Name = "clientValue";
s.Id = 1;
s.ClassId = 2;
var data = JSON.stringify(s);
console.log(data);

Deserialization:

eval will

String

Deserialized into Object

var s = eval('(' + data+ ')');
console.log(s.Name);
Complete example:




  
  json序列化与反序列化




The running effect is as follows:

The above is the detailed content of Example of javascript implementation of json serialization and deserialization functions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn