想用批处理从json文件只提取指定字段的值,提取是成功了,但不知道为什么for语句不执行 do 里面的代码,是哪里写错了嘛?
cscript 部分的代码是从网上抄的,我对cscript执行代码完全小白。
这是 json 文件内容:- {"media_type":2,"has_dash_audio":true,"is_completed":true,"total_bytes":37080115,"downloaded_bytes":37080115,"title":"七年级上册地理《世界气候类型的分布》人教版,提炼知识点,快速提分版,期中复习重点知识,帮助孩子归纳总结,地理逆袭考高分","type_tag":"116","cover":"http:\/\/i2.hdslb.com\/bfs\/archive\/db711b3345dc0f2c2e546d9586433484d19d0b78.jpg","video_quality":116,"prefered_video_quality":116,"guessed_total_bytes":0,"total_time_milli":415775,"danmaku_count":7,"time_update_stamp":1726490604122,"time_create_stamp":1726490595210,"can_play_in_advance":true,"interrupt_transform_temp_file":false,"quality_pithy_description":"1080P","quality_superscript":"60帧","variable_resolution_ratio":false,"cache_version_code":8130300,"preferred_audio_quality":0,"audio_quality":0,"avid":747920231,"spid":0,"seasion_id":0,"bvid":"BV1yC4y1E77K","owner_id":1865370698,"owner_name":"启梦学霸课堂","owner_avatar":"https:\/\/i2.hdslb.com\/bfs\/face\/c8722a5d4c191feae51be4966c5585b76f5b5173.jpg","is_charge_video":false,"verification_code":0,"page_data":{"cid":1319882112,"page":1,"from":"vupload","part":"七年级上册地理《世界气候类型的分布》人教版,提炼知识点,快速提分版,期中复习重点知识,帮助孩子归纳总结,地理逆袭考高分","link":"","rich_vid":"","vid":"","has_alias":false,"tid":208,"width":1080,"height":1920,"rotate":0,"download_title":"视频已缓存完成","download_subtitle":"七年级上册地理《世界气候类型的分布》人教版,提炼知识点,快速提分版,期中复习重点知识,帮助孩子归纳总结,地理逆袭考高分"}}
复制代码 这是批处理代码:- @echo off
- setlocal EnableDelayedExpansion
- color a
- rem 从一个json文件中提取指定内容
-
-
- >"%tmp%\j.js" echo;var m=WSH.StdIn.ReadAll().match(/("title"):"[^"]+"/);if(m){WSH.StdErr.WriteLine(m[0]);}
-
- for /f %%i in ('type entry.json ^| cscript //B //nologo //e:jscript "%tmp%\j.js"') do (
- set txt=%%i11111
- echo !txt:9,-1!
- )
- pause
- exit
复制代码
|