什么是JSON中的反序列化和序列化? [英] What is deserialize and serialize in JSON?

查看:893
本文介绍了什么是JSON中的反序列化和序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到用JSON进行术语反序列化"和序列化".是什么意思?

I have seen the terms "deserialize" and "serialize" with JSON. What do they mean?

推荐答案

JSON是一种将对象编码为字符串的格式. 串行化表示将对象转换为该字符串,然后反序列化是其反操作(转换字符串->对象).

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object).

在传输数据或将其存储在文件中时,数据必须是字节字符串,但是很少有这种格式的复杂对象.序列化可以将这些复杂的对象转换为字节字符串以供此类使用.字节字符串发送后,接收方将不得不从字节字符串中恢复原始对象.这就是所谓的反序列化.

When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom in this format. Serialization can convert these complex objects into byte strings for such use. After the byte strings are transmitted, the receiver will have to recover the original object from the byte string. This is known as deserialization.

说,您有一个对象:

{foo: [1, 4, 7, 10], bar: "baz"}

序列化为JSON会将其转换为字符串:

serializing into JSON will convert it into a string:

'{"foo":[1,4,7,10],"bar":"baz"}'

可以存储或通过电线发送到任何地方.然后,接收者可以反序列化此字符串以取回原始对象. {foo: [1, 4, 7, 10], bar: "baz"}.

which can be stored or sent through wire to anywhere. The receiver can then deserialize this string to get back the original object. {foo: [1, 4, 7, 10], bar: "baz"}.

这篇关于什么是JSON中的反序列化和序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆