shell处理json数据

#!/bin/bash
function
get_json(){ echo "${1//\"/}" | sed "s/.*$2:\([^,}]*\).*/\1/" } function deal_json(){ cmd="curl -s http://127.0.0.1:28888/aibox/server/version" echo ${cmd} # 打印 api_result=`eval ${cmd}` # 执行cmd,拿到返回的结果 echo ${api_result} # 打印 value=$(get_json "${api_result}" "version") # 从api_result中获取status对应的值 echo ${value} # 打印200 value=$(get_json "${api_result}" "version1") # 从api_result中获取status对应的值 echo ${value} # 打印200 } deal_json deal_jso

 

posted @ 2022-12-07 16:03  Leonardo-li  阅读(2670)  评论(0编辑  收藏  举报