• 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解析成对象的形式

    let url = 'method=query_sql_dataset_data&projectId=85&appToken=7d22e38e-5717-11e7-907b-a6006ad3dba0';
     qs.parse(url);//
    {method: "query_sql_dataset_data", projectId: "85", appToken: "7d22e38e-5717-11e7-907b-a6006ad3dba0"}
    四、qs.stringify(  )将对象解析成URL的形式
    let obj= {method: "query_sql_dataset_data", projectId: "85", appToken: "7d22e38e-5717-11e7-907b-a6006ad3dba0", datasetId: " 12564701"};
    qs.stringify( obj)//
    {method: "query_sql_dataset_data", projectId: "85", appToken: "7d22e38e-5717-11e7-907b-a6006ad3dba0", datasetId: " 12564701"}
  • 相关阅读:
    Buffer Lock Mode and Compatibilities
    11g默认审计选项
    11.2.0.2 asmcmd lsdg show incorrect diskgroup number
    关于V$OPEN_CURSOR
    了解你所不知道的SMON功能(七):清理IND$字典基表
    PL/SQL DEPENDENCIES
    温习 Linux 命令
    温习 SQL 03
    PL/SQL 基础 ( 下 )
    HTML501 ( The.Essential.Guide )
  • 原文地址:https://www.cnblogs.com/LSSSunshine/p/7340573.html
Copyright © 2020-2023  润新知