JSON Stringify示例–如何使用JS解析JSON对象

There are so many programming languages, and every language has its own features. But all of them have one thing in common: they process data. From a simple calculator to supercomputers, they all work on data.

编程语言种类繁多,每种语言都有自己的功能。 但是所有这些都有一个共同点:它们处理数据。 从简单的计算器到超级计算机,它们都可以处理数据。

It's the same with humans: there are so many countries, so many cultures, and so much knowledge within each community.

人类也是如此:每个社区内有如此众多的国家,如此众多的文化和众多的知识。

But to communicate with other communities, people need a common medium. Language is to humans what JSON is to programming, a common medium of data transmission.

但是,要与其他社区进行交流,人们需要一种通用的媒介。 语言对人类而言,JSON对编程而言,是一种通用的数据传输媒介。

什么是JSON? (What is JSON?)

JSON stands for JavaScript Object Notation. So before understanding JSON let's understand objects in JavaScript.

JSON代表的J ava 小号 CRIPTöbjectÑ浮选。 因此,在了解JSON之前,让我们了解JavaScript中的对象。

Every programming language has some method of storing similar data together. In C, for example, they are called structures.

每种编程语言都有一些将相似数据存储在一起的方法。 例如,在C中,它们称为结构。

In JavaScript, objects are a collection of key-value pairs, where values can be any variable (number, string, boolean), another object, or even a function. Objects are very useful in object-oriented programming.

在JavaScript中,对象是键值对的集合,其中值可以是任何变量(数字,字符串,布尔值),另一个对象,甚至是一个函数。 对象在面向对象的编程中非常有用。

Object-oriented programming is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields, and code, in the form of procedures.

面向对象的编程是一种基于“对象”概念的编程范式,它可以包含字段形式的数据和过程形式的代码。

Let's look at an example.

让我们来看一个例子。

In JavaScript, objects are defined using curly braces, for example:

在JavaScript中,使用花括号定义对象,例如:

var obj = {};

Here, obj is an empty object. You can also create objects using constructors, for example:

在这里, obj是一个空对象。 您还可以使用构造函数创建对象,例如:

This would give the output Abhishek 123 18.

这将产生输出Abhishek 123 18

This is how you create objects in JavaScript. But these objects are still variables that are only specific to JavaScript.

这就是在JavaScript中创建对象的方式。 但是这些对象仍然是仅特定于JavaScript的变量。

If you want to export these objects, and for example send them to a server, you need a method to encode them. Let's see how it's done.

如果要导出这些对象,例如将它们发送到服务器,则需要一种对它们进行编码的方法。 让我们看看它是如何完成的。

JSON Stringify (JSON Stringify)

In order to transmit data from one device to another, and one language to another, we need a structured, uniform and well-defined convention.

为了将数据从一种设备传输到另一台设备,以及将一种语言传输到另一种语言,我们需要一种结构化,统一且定义明确的约定。

Though JSON is based on JS objects, certain conditions need to be valid. Luckily, you don't have to be worried about those conditions – because in JavaScript, we have a method called JSON.stringif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值