javascript - JS 过滤 JSON 响应
问题描述
不幸的是,我不熟悉 JS,我需要过滤这个字符串,例如:
{
"code":200,
"success":true,
"data":{
"token":".J1e9ipFZkPE6EvIRAqEf9hp",
"expires":"2019-01-05 14:18:43"
},
"time":0.009
}
很明显我需要获取令牌值,我发现在 XML 中有 jsonpath 就像 Xpath 一样,但我不知道在 JS 中这样做。
我想得到你的帮助
解决方案
你是这个意思吗?
const text = '{ "code":200, "success":true, "data":{ "token":".J1e9ipFZkPE6EvIRAqEf9hp", "expires":"2019-01-05 14:18:43" }, "time":0.009 }'
const json = JSON.parse(text);
const token = json.data.token
console.log(token)
推荐阅读
- javascript - 在引导日期时间选择器中更改 meridiem (am pm) 的文本
- database - QGIS Fieldtypes 布尔值
- pdf - 如何识别平面pdf中的复选框?
- scikit-learn - sklearn中的transformer和estimator有什么区别?
- batch-file - 创建具有多个命名参数的批处理文件
- python - 将数字列表映射到具有多个值的字典键
- python - Python中的递归是幂函数
- django-rest-framework - ModelSerializer 的响应中包含的字段
- java - Java - 使用 void 返回类型允许客户进入事件
- html - 无法以特定方式移动/动画我的 svg 徽标