JSON 格式错误

标签 json google-bigquery

尝试将此 JSON 导入 google bigquery 表时出现此错误
file-00000000: JSON 表遇到太多错误,放弃。行数:1;错误:1.(错误代码:无效)
从文件位置 0 开始的行中的 JSON 解析错误:file-00000000。在没有对象开始的情况下遇到数组开始。 (错误代码:无效)

这是 JSON

[{'instrument_token': 11192834, 'average_price': 8463.45, 'last_price': 8471.1, 'last_quantity': 75, 'buy_quantity': 1065150, 'volume': 5545950, 'depth': {'buy': [{'price': 8471.1, 'quantity': 300, 'orders': 131072}, {'price': 8471.0, 'quantity': 300, 'orders': 65536}, {'price': 8470.95, 'quantity': 150, 'orders': 65536}, {'price': 8470.85, 'quantity': 75, 'orders': 65536}, {'price': 8470.7, 'quantity': 225, 'orders': 65536}], 'sell': [{'price': 8471.5, 'quantity': 150, 'orders': 131072}, {'price': 8471.55, 'quantity': 375, 'orders': 327680}, {'price': 8471.8, 'quantity': 1050, 'orders': 65536}, {'price': 8472.0, 'quantity': 1050, 'orders': 327680}, {'price': 8472.1, 'quantity': 150, 'orders': 65536}]}, 'ohlc': {'high': 8484.1, 'close': 8336.45, 'low': 8422.35, 'open': 8432.75}, 'mode': 'quote', 'sell_quantity': 998475, 'tradeable': True, 'change': 1.6151959167271395}]

http://jsonformatter.org/还给出了这个 JSON 块的解析错误。需要帮助理解格式错误的地方 - 这是来自 rest API 的 JSON

最佳答案

这不是有效的 JSON。 JSON 使用双引号,而不是单引号。另外,True应该是 true .

如果我不得不猜测,我会猜测这是作为 JSON 传递的 Python 代码。 :-)

我怀疑即使将其制成正确的 JSON,它也不是 Google BigQuery 所期望的格式。来自 https://cloud.google.com/bigquery/data-formats#json_format ,看起来您应该有一个文本文件,每行一个 JSON 对象。试试这个:

{"mode": "quote", "tradeable": true, "last_quantity": 75, "buy_quantity": 1065150, "depth": {"buy": [{"quantity": 300, "orders": 131072, "price": 8471.1}, {"quantity": 300, "orders": 65536, "price": 8471.0}, {"quantity": 150, "orders": 65536, "price": 8470.95}, {"quantity": 75, "orders": 65536, "price": 8470.85}, {"quantity": 225, "orders": 65536, "price": 8470.7}], "sell": [{"quantity": 150, "orders": 131072, "price": 8471.5}, {"quantity": 375, "orders": 327680, "price": 8471.55}, {"quantity": 1050, "orders": 65536, "price": 8471.8}, {"quantity": 1050, "orders": 327680, "price": 8472.0}, {"quantity": 150, "orders": 65536, "price": 8472.1}]}, "change": 1.6151959167271395, "average_price": 8463.45, "ohlc": {"close": 8336.45, "high": 8484.1, "open": 8432.75, "low": 8422.35}, "instrument_token": 11192834, "last_price": 8471.1, "sell_quantity": 998475, "volume": 5545950}

关于JSON 格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38388415/

相关文章:

c# - 带有方法参数的 WCF webHttpBinding 错误。 "At most one body parameter can be serialized without wrapper elements"

google-bigquery - 如何使用标准 SQL 删除 BigQuery 中某个字符之后的所有字符?

google-bigquery - 某些 bigquery 公共(public)数据集是否不再可用?

google-cloud-platform - 您可以将 Google Cloud Web 控制台登录限制在某个 IP 地址范围内吗?

google-cloud-platform - 传输服务数据不一致: Google Ads (AdWords) <> BigQuery

regex - 错误 : Big Query REGEX_EXTRACT Cannot parse regular expression: invalid perl operator: (? <

ruby - 使用 Ruby 合并和更新 Redis 中的哈希键

java - 如何从 JSON 输出字符串中提取各个数据片段?

java - XML 到 JSON 产生不期望的结果

ios - 如何在 swift 2 中获取 Alamofire.request().responseJSON 的结果值?