如何从Windows Batch中的JSON文件获取并将其设置为变量一个值

汤米

所以,基本上我有一个JSON文件

{"date":"2020-01-25","explanation":"In this Hubble Space Telescope image the bright, spiky stars lie in the foreground toward the heroic northern constellation Perseus and well within our own Milky Way galaxy. In sharp focus beyond is UGC 2885, a giant spiral galaxy about 232 million light-years distant. Some 800,000 light-years across compared to the Milky Way's diameter of 100,000 light-years or so, it has around 1 trillion stars. That's about 10 times as many stars as the Milky Way. Part of a current investigation to understand how galaxies can grow to such enormous sizes, UGC 2885 was also part of astronomer Vera Rubin's pioneering study of the rotation of spiral galaxies. Her work was the first to convincingly demonstrate the dominating presence of dark matter in our universe.","hdurl":"https://apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst2000.jpg","media_type":"image","service_version":"v1","title":"Rubin's Galaxy","url":"https://apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst1024.jpg"}

这是NASA APOD Api。我想获取一个特定的“ hdurl”值并将其设置为批处理中的URL变量:“ https://apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst2000.jpg

然后,我希望它从该站点下载图像。

老实说,我不知道该怎么做。任何帮助将不胜感激!

不是我

您可以使用2次for循环:

第一个定界符:}for循环中,;(默认)在第二个for循环中2nd:

  • 在命令行中:
for /f tokens^=4*delims^=^:^} %i in ('type file.json')do for /f tokens^=1delims^=^"^  %I in ('echo/%i%j')do echo/%I && set "_imageURL=%I"
@echo off 

for /f tokens^=4*delims^=^:^} %%i in ('type file.json
')do for /f tokens^=1delims^=^"^  %%I in ('echo/%%i%%j')do echo/%%I && set "_imageURL=%%I"

  • 输出:
https//apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst2000.jpg

{"date":"2020-01-25","explanation":"In this Hubble Space Telescope image the bright, spiky stars lie in the foreground toward the heroic northern constellation Perseus and well within our own Milky Way galaxy. In sharp focus beyond is UGC 2885, a giant spiral galaxy about 232 million light-years distant. Some 800,000 light-years across compared to the Milky Way's diameter of 100,000 light-years or so, it has around 1 trillion stars. That's about 10 times as many stars as the Milky Way. Part of a current investigation to understand how galaxies can grow to such enormous sizes, UGC 2885 was also part of astronomer Vera Rubin's pioneering study of the rotation of spiral galaxies. Her work was the first to convincingly demonstrate the dominating presence of dark matter in our universe.","hdurl":"https://apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst2000.jpg","media_type":"image","service_version":"v1","title":"Rubin's Galaxy","url":"https://apod.nasa.gov/apod/image/2001/RubinsGalaxy_hst1024.jpg"}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何获取一个变量的值并将其设置为等于类中的另一个变量?

文本文件:如何获取string1和string2的下一个实例之间的文本并将其设置为Batch变量?

如何从txt文件中抓取一个随机单词并将其设置为批处理中的变量

如何获取 txt 文件的第一行并将其设置为 Batch 中的 %variable%?

如何获取JSON值并将其保存在JS中的另一个文件中

如何获得双向数据绑定值并将其设置在另一个变量中

我将如何从输入中获取值,将其舍入到下一个偶数并将其设置为新变量

如何获取html值并将其设置为java变量

如何在 BigQuery 中声明一个变量并将其设置为 EXTERNAL_QUERY 的参数?

Windows/CLI | 在文件中搜索特定字符串/值并将其设置为变量

我有一个带有值的数据框,并将其设置为Excel中的范围,如何隐藏索引?

如何将一个值设置为一个类中的变量并从另一个类中获取该变量的值?

如何使用节点 js (socket.io) 在一个文件中的函数内获取变量并将其传递给另一个文件?

如何从输出中获取特定行并将其保存在一个变量中?

我们如何 grep 一个值并将其存储在 powershell 中的变量中?

如何从变量中获取数据并将其放入另一个

如何合并多个文件中的命名导出并将其导出为一个对象

如何清理JSON文件并将其存储到Python中的另一个文件

我如何在python中设置一个值并获取一个值/变量?

如何从表中检索行并将其值设置为json数组并获取该json数组作为返回值

如何从 TextInput(在 expo 中)获取输入并将其存储为变量,以便在不使用类的情况下在另一个函数中调用?

如何获取当前的edittext的文本(字体)样式并将其设置为另一个edittext?

如何将用户的 JSON 文件中的项目导入 HTML 并将每个值设置为变量

如何使用 $_GET 从 url 获取变量并将其设置为下拉列表的默认值

如何检查变量是否具有相同的值并将其作为一个值在python中返回

如何从一个脚本中获取变量的值,然后将其导入另一个脚本中?

如何从数据库中获取多个数据并将其存储在一个变量中?

如何将哈希值中的数据存储在文件中并将其用于另一个哈希值

如何从HTML中的元素内部获取值并将其设置为JS中的变量