{"id":1107,"date":"2021-10-13T12:19:31","date_gmt":"2021-10-13T12:19:31","guid":{"rendered":"http:\/\/www.liutianfeng.com\/?p=1107"},"modified":"2021-10-14T10:41:01","modified_gmt":"2021-10-14T10:41:01","slug":"shell%e8%a7%a3%e6%9e%90json%e5%92%8cxml","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=1107","title":{"rendered":"shell\u89e3\u6790json\u548cxml"},"content":{"rendered":"<h1>\u4e00. json\u89e3\u6790<\/h1>\n<p>\u5b9e\u4f8bjson:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">{\r\n  \"status\": \"0000\",\r\n  \"message\": [\r\n    \"success\",\r\n    \"failed\"\r\n  ],\r\n  \"data\": {\r\n    \"title\": {\r\n      \"id\": \"001\",\r\n      \"name\": \"\u767d\u83dc\"\r\n    },\r\n    \"content\": [\r\n      {\r\n        \"id\": \"001\",\r\n        \"value\": \"\u4f60\u597d \u767d\u83dc\"\r\n      },\r\n      {\r\n        \"id\": \"002\",\r\n        \"value\": \"\u4f60\u597d \u841d\u535c\"\r\n      }\r\n    ]\r\n  }\r\n}<\/code><\/pre>\n<p>\u8303\u4f8b:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">&gt; cat a.json |jq '.status'   # \u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u4e00\u4e2a\u503c\r\n\"0000\"\r\n&gt; cat a.json |jq '.data.title.name'  # \u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u5d4c\u5957\u503c\r\n\"\u767d\u83dc\"\r\n&gt; cat a.json |jq '.data.content[0].id'   # \u83b7\u53d6\u5b57\u5178\u4e2d\u5b50\u5217\u8868\u4e2d\u7684\u5d4c\u5957\u503c, \u5217\u8868\u7528index\u83b7\u53d6\r\n\"001\"<\/code><\/pre>\n<p>jq\u5e2e\u52a9:<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">&gt; jq --help\r\njq - commandline JSON processor [version 1.6]\r\n\r\nUsage:\tjq [options] &lt;jq filter&gt; [file...]\r\n\tjq [options] --args &lt;jq filter&gt; [strings...]\r\n\tjq [options] --jsonargs &lt;jq filter&gt; [JSON_TEXTS...]\r\n\r\njq is a tool for processing JSON inputs, applying the given filter to\r\nits JSON text inputs and producing the filter's results as JSON on\r\nstandard output.\r\n\r\nThe simplest filter is ., which copies jq's input to its output\r\nunmodified (except for formatting, but note that IEEE754 is used\r\nfor number representation internally, with all that that implies).\r\n\r\nFor more advanced filters see the jq(1) manpage (\"man jq\")\r\nand\/or https:\/\/stedolan.github.io\/jq\r\n\r\nExample:\r\n\r\n\t$ echo '{\"foo\": 0}' | jq .\r\n\t{\r\n\t\t\"foo\": 0\r\n\t}\r\n\r\nSome of the options include:\r\n  -c               compact instead of pretty-printed output;\r\n  -n               use `null` as the single input value;\r\n  -e               set the exit status code based on the output;\r\n  -s               read (slurp) all inputs into an array; apply filter to it;\r\n  -r               output raw strings, not JSON texts;\r\n  -R               read raw strings, not JSON texts;\r\n  -C               colorize JSON;\r\n  -M               monochrome (don't colorize JSON);\r\n  -S               sort keys of objects on output;\r\n  --tab            use tabs for indentation;\r\n  --arg a v        set variable $a to value &lt;v&gt;;\r\n  --argjson a v    set variable $a to JSON value &lt;v&gt;;\r\n  --slurpfile a f  set variable $a to an array of JSON texts read from &lt;f&gt;;\r\n  --rawfile a f    set variable $a to a string consisting of the contents of &lt;f&gt;;\r\n  --args           remaining arguments are string arguments, not files;\r\n  --jsonargs       remaining arguments are JSON arguments, not files;\r\n  --               terminates argument processing;\r\n\r\nNamed arguments are also available as $ARGS.named[], while\r\npositional arguments are available as $ARGS.positional[].\r\n\r\nSee the manpage for more options.<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>xml:\u00a0https:\/\/www.jb51.net\/article\/125887.htm<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=1107\">shell\u89e3\u6790json\u548cxml<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u4e00. json\u89e3\u6790 \u5b9e\u4f8bjson: { &#8220;status&#8221;: &#8220;0000&#8221;, &#8220;message&#8221;: [ &#8220;suc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1107"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1107"}],"version-history":[{"count":3,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions"}],"predecessor-version":[{"id":1111,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions\/1111"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}