gpt4 book ai didi

javascript - 从 JSON 中删除垃圾?

转载 作者:行者123 更新时间:2023-11-28 13:50:50 25 4
gpt4 key购买 nike

对于 IE7 和 IE8,我正在捕获一些 JSONp 以在我的网页中使用。以下是 JSONP 的摘录:

{
class: "min-temp",
span: {
class: "units-values temperature-units-values",
span: [
{
class: "units-value temperature-value temperature-value-unit-c",
span: {
class: "unit",
content: "°C"
},
content: "11
"
},
{
class: "units-value temperature-value temperature-value-unit-f",
span: {
class: "unit",
content: "°F"
},
content: "52
"
}
]
}
},

如果你查看content: "11content: "52,你会发现它们后面有很多额外的字符。如何删除这些多余的字符,以便最终只得到数字,即 1152

目前,我按如下方式提取这些数字:

day.span[1].span.span[0].content 给我 11day.span[1].span.span[ 1].content 给我 52

最佳答案

如果您只期望那里的整数值,只需使用 parseInt 。它将忽略空格。

关于javascript - 从 JSON 中删除垃圾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11085079/

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