> For the complete documentation index, see [llms.txt](https://note.niefee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://note.niefee.com/summary-1/10/2015-nian-10-yue-31-ri.md).

# 2015年10月31日

## json

名称/值对组合中的名称写在前面（**在双引号中**），值对写在后面(**同样在双引号中**)，中间用冒号隔开：

```
{"firstName":"John"}
```

var dataObj=eval("("+data+")");//转换为json对象

> 加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式（expression）转化为对象，而不是作为语句（statement）来执行。

```javascript
  //示例1：此示例使用 JSON.parse 将 JSON 字符串转换为对象  
    var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';  
    var contact = JSON.parse(jsontext);  
    document.write(contact.surname + ", " + contact.firstname + ", "+ contact.phone);
```

> 建议使用JSON.parse（），eval（）存在安全隐患。
