javascript - 解析我的 json 以获取值 - 从 Xcode 发送到 JS 前端的 json
问题描述
试图解析和读取我的 JSON 数据。
我正在将我的 json 数据从 Xcode 传递到我的 React 本机前端。
我试过 JSON.parse 和 JSON.stringify 没有任何效果。
它总是记录“NULL”。我需要访问“价值”帮助!
Xcode 中的 JSON
{
"myDictionary" : {
"BG" : [
"{\"value\":\"8 mg\\\/dL\",\"endDate\":635390040,\"startDate\":635390040,\"type\":\"bloodGlucose\"}",
"{\"value\":\"6 mg\\\/dL\",\"endDate\":635393640,\"startDate\":635393640,\"type\":\"bloodGlucose\"}"
]
}
}
JS:
const log = HealthkitController.getBloodGlucose()
.then(result => {
let res = JSON.parse(result)
for (let i = 0; i < res.length; i++) {
let final = res[0];
console.log(final) // prints the first object
let fin = final["value"]
console.log(fin) //undefined (doesn't print 8mg/dL)
}
})
结果:
["{\"value\":\"8 mg\\\/dL\",\"endDate\":635390040,\"startDate\":635390040,\"type\":\"bloodGlucose\"}",
"{\"value\":\"6 mg\\\/dL\",\"endDate\":635393640,\"startDate\":635393640,\"type\":\"bloodGlucose\"}"]
解决方案
这创造了什么?
const log = HealthkitController.getBloodGlucose()
.then(result => {
for (var i = 0; i < result.lenght; i++{
let res = JSON.parse(result[i])
console.log(res) //always null
}
});
推荐阅读
- javascript - 在javascript中定义具有不同参数列表的函数是一种好习惯吗?
- java - 使用 Jersey 的 REST API 上的 POST 请求未更新存储库中的列表,即未添加已发布的新对象
- sql - SQL查询获取每个员工的第一拳和最后一拳
- recursion - 需要帮助解决不平衡的递归树问题
- sql-server - 基于复杂静态 SQL 迭代所有列的动态 SQL
- ios - 使用版本 Xcode 11.4 构建 Xcode 项目时反复出错
- vaadin - 在 Vaadin Flow 中更改组件图标
- swift - TableView 创建重复单元格
- java - java.lang.NoSuchMethodError: 'com.google.api.client.json.JsonParser
- python - tensorflow v1 可以用于部署吗?