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

查看:40
本文介绍了什么是 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.

比如说,你有一个对象:

Say, you have an object:

{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天全站免登陆