请原谅我说英语,我不是以英语为母语的人

我有一个json文件"VideoJson.json",其中包含以下内容

VideoJSONLoaded({"video_type": "0","image_id": "0","profile": false,"published_urls": [{"embed_url": "https://alura.hls/vod/p/manifest/55.mpd","protocol": "https","cdn_name": "Cloud","state": 10,"live_url": "https://alura.hls/vod/p/manifest/55.mpd"}],"access_rules": "{}","timed_cues": [],"embedded_cc": 1,"adst_temp_ver": "2"})

我try 使用以下命令读取带有Xidel的json

xidel-0.9.8.x32 "VideoJson.json" -e "$json"

我收到一条错误信息

Error: jerr:JNDY0021: error at VideoJSONLoaded (tkIdentifier) in VideoJSONLoaded...

我想这是因为json在VideoJSONLoaded(JSON)以内

我应该使用什么命令才能正确读取json并提取数据?

推荐答案

不管是什么工具提供的,这个文件都做得很糟糕,因为它根本不是JSON.

当你打开"*"时.json’文件,xidel采用json(--input-format=json).如果不是,则必须用--input-format=text覆盖它(对于v0.9.8,--input-format=html):

xidel -s --input-format=text "VideoJson.json" -e "$raw"
VideoJSONLoaded({"video_type": "0",[...],"adst_temp_ver": "2"})

要提取JSON,可以使用substring-before()substring-after():

xidel -s --input-format=text "VideoJson.json" -e "substring-before(substring-after($raw,'VideoJSONLoaded('),')')"
{"video_type": "0",[...],"adst_temp_ver": "2"}

extract():

xidel -s --input-format=text "VideoJson.json" -e "extract($raw,'\{.+\}')"
{"video_type": "0",[...],"adst_temp_ver": "2"}

最后是parse-json()(v0.9.8版本为json())来解析JSON:

xidel -s --input-format=text "VideoJson.json" -e "parse-json(extract($raw,'\{.+\}'))"
{
  "video_type": "0",
  "image_id": "0",
  "profile": false,
  "published_urls": [
    {
      "embed_url": "https://alura.hls/vod/p/manifest/55.mpd",
      "protocol": "https",
      "cdn_name": "Cloud",
      "state": 10,
      "live_url": "https://alura.hls/vod/p/manifest/55.mpd"
    }
  ],
  "access_rules": "{}",
  "timed_cues": [],
  "embedded_cc": 1,
  "adst_temp_ver": "2"
}

Json相关问答推荐

在Go中,当字段可以根据其他字段具有不同的类型时,什么是正确的方法来卸载JSON?

按照对象键的值对PostgreSQL JSONB对象进行排序'

将json数组反序列化为选项 struct

Jolt变换将字段移动到数组的每个元素中

XSLT 3.0 Json-to-xml,json 包含 html struct

将 GEOSwift.JSON 转换为 Swift 中的 struct

VBA-JSON 嵌套集合解析为 Excel

如何加入或合并列表元素列表(未知长度)

我如何将 JSON 格式与 flutter 一起使用?帮助使用 Gamebanana api

用powershell条件解析json文件的数组对象

如何实现一个通用的 serde_json::from_str

提交后使用 Rails 7 结合 JSON 标签进行标记

如果 jq 数组中的字符串是对象或字符串,则获取值

使用 jq 将键值行转换为 json

Flask 请求和 application/json 内容类型

如何自动修复无效的 JSON 字符串?

如何在已声明的 JSON 对象中添加键值对

从 JSON 创建 Hashtable

通过url获取json数据并在python中使用(simplejson)

Backbone.js 模型与集合