博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Array JSON
阅读量:5235 次
发布时间:2019-06-14

本文共 1434 字,大约阅读时间需要 4 分钟。

Tool:

JSON: JavaScript Object Notation.

JSON is a syntax for storing and exchanging data.

JSON Objects

JSON objects are written inside curly braces.

{"name":"John", "age":25, "japanese":false}

JSON Arrays

JSON arrays are written inside square brackets.

"employees":[    {
"firstName":"John", "lastName":"Doe"}, {
"firstName":"Anna", "lastName":"Smith"}, {
"firstName":"Peter","lastName":"Jones"}]

JSON Uses JavaScript Syntax

var employees = [    {
"firstName":"John", "lastName":"Doe"}, {
"firstName":"Anna", "lastName":"Smith"}, {
"firstName":"Peter","lastName": "Jones"}];

Be accessed:

// returns John Doeemployees[0].firstName + " " + employees[0].lastName;// returns John Doeemployees[0]["firstName"] + " " + employees[0]["lastName"];

Be modified

employees[0].firstName = "Gilbert";employees[0]["firstName"] = "Gilbert";

Object From String: Create a JavaScript string containing JSON syntax

var text = '{ "employees" : [' +'{ "firstName":"John" , "lastName":"Doe" },' +'{ "firstName":"Anna" , "lastName":"Smith" },' +'{ "firstName":"Peter" , "lastName":"Jones" } ]}';

The JavaScript function JSON.parse(text) can be used to convert a JSON text into a JavaScript object:

// Normal browsersvar obj = JSON.parse(text);// Older browsersvar obj = eval ("(" + text + ")");// Outputobj.employees[1].firstName + " " + obj.employees[1].lastName

以上です

转载于:https://www.cnblogs.com/hzj680539/p/5052074.html

你可能感兴趣的文章
网站产品设计
查看>>
TCP/IP协议
查看>>
如何修改被编译后DLL文件 (转发)
查看>>
C++按格式接收输入字符(京东,滴滴,360笔试必用)
查看>>
代理ARP
查看>>
go 学习笔记(4) ---项目结构
查看>>
分割线细线
查看>>
java 中的一些运算符问题
查看>>
css切换--使用cookie
查看>>
java中静态代码块的用法 static用法详解
查看>>
Java线程面试题
查看>>
Paper Reading: Relation Networks for Object Detection
查看>>
Android中点中overlay弹出带尾巴的气泡的实现
查看>>
Mybatis接口中传递多个参数
查看>>
Dreamweaver层使用八定律
查看>>
Java IO流学习总结
查看>>
day22 01 初识面向对象----简单的人狗大战小游戏
查看>>
数组的几种常用方法总结
查看>>
递归函数,二分运算,正则表达式
查看>>
阅读软件工程的问题
查看>>