qs.parse()qs.stringify()JSON.parse()JSON.stringify()使用方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了qs.parse()qs.stringify()JSON.parse()JSON.stringify()使用方法相关的知识,希望对你有一定的参考价值。
一、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解析成对象的形式
以上是关于qs.parse()qs.stringify()JSON.parse()JSON.stringify()使用方法的主要内容,如果未能解决你的问题,请参考以下文章