Parse simple JSON string in Batch

后端 未结 5 1891
执笔经年
执笔经年 2020-12-16 00:36

How do you parse a simple JSON string in Batch?

For example, if I have the following JSON string:

{ \"...\":\"...\", \"year\": 2016, \"time\": \"05:01\

5条回答
  •  星月不相逢
    2020-12-16 00:55

    There are different ways, here's one.

    @echo off
    set string={ "year": 2016, "time": "05:01" }
    set string=%string:"=%
    
    for /f "tokens=3,5" %%a in ('echo %string%') do set d=%%a&set t=%%b
    echo -%d%- -%t%-
    pause & goto :EOF
    

    and here's a second:

    @echo off
    set string={ "year": 2016, "time": "05:01" }
    
    for /f "tokens=3,5" %%a in ('echo %string%') do set d=%%~a&set t=%%~b
    echo -%d%- -%t%-
    pause & goto :EOF
    

提交回复
热议问题