請原諒我的英語,我不是母語人士
我有一個包含以下內容的 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"})
我嘗試使用以下命令使用 Xidel 讀取 json
xidel-0.9.8.x32 "VideoJson.json" -e "$json"
我收到一條錯誤訊息
Error: jerr:JNDY0021: error at VideoJSONLoaded (tkIdentifier) in VideoJSONLoaded...
我認為這是因為 json 在里面VideoJSONLoaded(JSON)
我應該使用什么命令才能正確讀取 json 并能夠提取資料?
uj5u.com熱心網友回復:
無論為您提供什么工具,這個檔案都做得不好,因為它根本不是 JSON。
當您打開“*.json”檔案時,xidel假定為 JSON ( --input-format=json)。如果不是,那么您必須使用--input-format=text(--input-format=html對于 v0.9.8)覆寫它:
xidel -s --input-format=text "VideoJson.json" -e "$raw"
VideoJSONLoaded({"video_type": "0",[...],"adst_temp_ver": "2"})
要提取 JSON,您可以使用substring-before()and 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()(json()對于 v0.9.8)決議 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"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/463401.html
上一篇:再次:JsonSerializationException:無法找到用于“自定義類”型別的建構式
下一篇:合并可選的嵌套陣列值以創建新物件
