gpt4 book ai didi

Ruby JSON 解析器证明不喜欢空格?

转载 作者:数据小太阳 更新时间:2023-10-29 08:41:17 27 4
gpt4 key购买 nike

我使用的是 json_pure-1.4.6,它在解析来自 Chrome 的 SpeedTracer 的数据时遇到问题。特别是它失败了:

705: unexpected token at '{"type":2147483642,"time":8872.551025390625,"data":{"identifier":1,"time":1295485209.698246,"request":{"url":"http://localhost:3000/login/new","httpMethod":"GET","httpHeaderFields":{"User-Agent":"Mozilla/5.0'

这显然是一个不完整的陈述,但在文件本身中它看起来像这样:

{"type":2147483642,"time":8872.551025390625,"data":{"identifier":1,"time":1295485209.698246,"request":{"url":"http://localhost:3000/login/new","httpMethod":"GET","httpHeaderFields":{"User-Agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.634.0 Safari/534.16","Accept":"application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"}},"redirectResponse":{"isNull":true}},"sequence":116}

我尝试通过 JSONLint 运行它并且它没有提示:

{
"type": 2147483642,
"time": 8872.551025390625,
"data": {
"identifier": 1,
"time": 1295485209.698246,
"request": {
"url": "http://localhost:3000/login/new",
"httpMethod": "GET",
"httpHeaderFields": {
"User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.634.0 Safari/534.16",
"Accept": "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
}
},
"redirectResponse": {
"isNull": true
}
},
"sequence": 116
}

由于它在空白处失败,我尝试删除“User-Agent”行中的所有空白,然后 json_pure 解析它没有错误。这是一个 json_pure 错误吗?

最佳答案

我只是将 JSON 字符串粘贴到一个文件中,然后运行:

require 'rubygems'
require 'json/pure'
str = File.open('pasted.json').read
x = JSON.parse(str)

...并得到预期值,没有错误。

ruby -v
=> ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin9.8.0]
gem list json_pure
=> json_pure (1.4.6)

很明显,您的设置有些古怪,但我不知道是什么。

关于Ruby JSON 解析器证明不喜欢空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4742739/

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