一、JSON.parse(用于从一个字符串中解析出json 对象)ps:单引号写在{}外,每个属性都必须双引号,否则会抛出异常
let str = '[{"field":"thedate","v1":"20170102"},{"field":"rev_type","v1":"大数据收入"},{"field":"thismonth","v1":"201708"},{"field":"nextmonth","v1":"201709"},{"field":"depart_type","v1":"leader"},{"field":"admin_emp_id","v1":"role"}]';
JSON.parse(str);//str必须满足引号使用规范,即:双引号和单引号相互嵌套
[
{field: "thedate", v1: "20170102"},
{field: "rev_type", v1: "大数据收入"},
{field: "thismonth", v1: "201708"},
{field: "nextmonth", v1: "201709"},
{field: "depart_type", v1: "leader"},
{field: "admin_emp_id", v1: "role"}
]
二、JSON.stringify(用于从一个对象解析出字符串)
let arr=[
{field: "thedate", v1: "20170102"},
{field: "rev_type", v1: "大数据收入"},
{field: "thismonth", v1: "201708"},
{field: "nextmonth", v1: "201709"},
{field: "depart_type", v1: "leader"},
{field: "admin_emp_id", v1: "role"}
]
JSON.stringify(arr);//全是双引号
"[{"field":"thedate","v1":"20170102"},{"field":"rev_type","v1":"大数据收入"},{"field":"thismonth","v1":"201708"},{"field":"nextmonth","v1":"201709"},{"field":"depart_type","v1":"leader"},{"field":"admin_emp_id","v1":"role"}]"
三、qs.parse()将URL解析成对象的形式