gpt4 book ai didi

javascript - 如何在 Node js 中从 json 格式中拆分字符串

转载 作者:行者123 更新时间:2023-11-30 11:14:37 25 4
gpt4 key购买 nike

我是 Node.js 的新手,这是我的示例 json 格式数据。我想将它们拆分成 json 格式,需要获取 tid 值。在 node.js 中,我尝试使用 JSON.parse(data) 但它发生了错误(因为 [] 符号)。有没有一种简单的方法将它们拆分成json格式并获取tid值?

[{"date":1535624757,"date_ms":1535624757427,"amount":90.389717,"price":0.00860497,"type":"buy","tid":251916659},{"date":1535624757,"date_ms":1535624757428,"amount":99.428689,"price":0.00860497,"type":"buy","tid":251916662},{"date":1535624757,"date_ms":1535624757469,"amount":384.65968,"price":0.00860497,"type":"buy","tid":251916663}]

最佳答案

JSON.parse 接受一个字符串变量,

[
{
"date": 1535624757,
"date_ms": 1535624757427,
"amount": 90.389717,
"price": 0.00860497,
"type": "buy",
"tid": 251916659
},
{
"date": 1535624757,
"date_ms": 1535624757428,
"amount": 99.428689,
"price": 0.00860497,
"type": "buy",
"tid": 251916662
},
{
"date": 1535624757,
"date_ms": 1535624757469,
"amount": 384.65968,
"price": 0.00860497,
"type": "buy",
"tid": 251916663
}
]

您管理的这段代码是对象变量。

你可以用这个

var data = JSON.parse('[{"date":1535624757,"date_ms":1535624757427,"amount":90.389717,"price":0.00860497,"type":"buy","tid":251916659},{"date":1535624757,"date_ms":1535624757428,"amount":99.428689,"price":0.00860497,"type":"buy","tid":251916662},{"date":1535624757,"date_ms":1535624757469,"amount":384.65968,"price":0.00860497,"type":"buy","tid":251916663}]')
console.log(data)

关于javascript - 如何在 Node js 中从 json 格式中拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52107543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com