<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[[实践OK]通过命令行能不能打印易读的Json数据怎么办？接合windows使用curl命令输出json并格式化的方法。及升级CentOS下的python到3.3版本的步骤，升级后yum except KeyboardInterrupt, e: 错误。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Mon, 09 Mar 2015 09:31:26 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：我很喜欢在命令行调试API，返回数据都是JSON格式的。打印出来的内容太痛苦了，如：&#123;&quot;status&quot;:200,&quot;data&quot;:[&#123;&quot;id&quot;:1000,&quot;name&quot;:&quot;John&quot;&#125;&#123;&quot;id&quot;:1004,&quot;name&quot;:&quot;Tom&quot;&#125;]&#125;，有木有工具打印个易读的样式，这样的<br/><textarea name="code" class="php" rows="15" cols="100">
&#123;
&nbsp;&nbsp;&quot;status&quot;:200,
&nbsp;&nbsp;&quot;data&quot;:
&nbsp;&nbsp;[
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;id&quot;:1000,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;name&quot;:&quot;John&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;,
&nbsp;&nbsp;&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;id&quot;:1004,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;name&quot;:&quot;Tom&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;]
&#125;
</textarea><br/><br/>实践一：<br/>答：可以使用python的json.tool！<br/>cat json&#124;python -mjson.tool<br/><br/>cat json&#124;python -mjson.tool<br/>python: module json.tool not found<br/>json是python3内置模块,在包libpython3.3-stdlib中提供。<br/>centOS的默认的python版本是V2.4.3，但运行json库也好需要的版本是3以上，linux（CentOS）下升级python3.3：<br/>http://lovebeyond.iteye.com/blog/1770476 ，后面升级后就Ok了，自带这个包，相当靠谱~&nbsp;&nbsp;AddTime：2015-03-09<br/><br/><br/>echo &#039;&#123;&quot;status&quot;:200,&quot;data&quot;:[&#123;&quot;id&quot;:1000,&quot;name&quot;:&quot;John&quot;&#125;,&#123;&quot;id&quot;:1004,&quot;name&quot;:&quot;Tom&quot;&#125;]&#125;&#039;&#124;python -mjson.tool<br/>Vim中格式化json数据：<br/>命令模式下<br/>#!python -m json.tool<br/>可以映射快捷键，如Ctrl+F6，编辑vimrc：<br/><br/>“ Format JSON data using python module json.tool<br/>map &lt;C-F6&gt; :#!python -m json.tool&lt;CR&gt;<br/><br/>vim调用python格式化json数据：<br/><br/><br/>实践二，根据1接合windows使用curl命令输出json并格式化的方法：<br/>windows中使用curl命令需要下载curl工具<br/><br/>下载地址：http://curl.haxx.se/download.html<br/><br/>请选择不带SSL的版本，否则还需要安装SSL的支持包<br/><br/>我下载的版本 http://www.paehl.com/open_source/?CURL_7.28.1<br/>下载后解压，将exe文件拷贝到 C:&#92;windows&#92;system32目录下即可在cmd中直接调用<br/><br/>我使用linux下成功的相同命令去发现报错如下：<br/><br/><br/><br/>网上查发现是引号的原因，<br/><br/>例如linux下成功命令格式如下：<br/><textarea name="code" class="php" rows="15" cols="100">
curl -X POST -d&nbsp;&nbsp;&#039;&#123;&quot;auth&quot;: &#123;&quot;tenantName&quot;: &quot;admin&quot;, &quot;passwordCredentials&quot;:&#123;&quot;username&quot;: &quot;admin&quot;, &quot;password&quot;: &quot;xxx&quot;&#125;&#125;&#125;&#039; -H &quot;Content-type: application/json&quot; http://192.168.xx.xx:35357/v2.0/tokens &#124; python -mjson.tool&nbsp;&nbsp;
windows下就应该如下：
curl -X POST -d&nbsp;&nbsp;&quot;&#123;&#92;&quot;auth&#92;&quot;: &#123;&#92;&quot;tenantName&#92;&quot;: &#92;&quot;admin&#92;&quot;, &#92;&quot;passwordCredentials&#92;&quot;:&#123;&#92;&quot;username&#92;&quot;: &#92;&quot;admin&#92;&quot;, &#92;&quot;password&#92;&quot;: &#92;&quot;xxx&#92;&quot;&#125;&#125;&#125;&quot; -H &quot;Content-type: application/json&quot; http://192.168.xx.xx:35357/v2.0/tokens &#124; python -mjson.tool&nbsp;&nbsp;
</textarea><br/>来自：http://blog.csdn.net/lipei1220/article/details/8536520<br/>http://blog.longwin.com.tw/2012/12/cli-python-json-formatter-2012/<br/>http://blog.csdn.net/yuechuzhao/article/details/24460781<br/>http://openwares.net/linux/vim_call_python_format_json.html<br/><br/><br/><br/><br/><br/><br/><br/>————————————————————linux（CentOS）下升级python3.3———————————————————————————<br/>CentOS下的Python版本一般都比较低，很多应用都需要升级python来完成。我装的centOS的默认的python版本是V2.4.3，但运行node.js需要的版本是2.5以上。 <br/><br/>1。下载python3.3安装包：wget http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz <br/><br/>2。解压安装包：tar -zxvf Python-3.3.0.tgz <br/>　　 <br/><br/>3。进入解压后目录：cd Python-3.3.0 <br/><br/><br/>4。创建安装目录：mkdir /usr/local/python3.3 <br/>　　 <br/><br/>5。编译安装：./configure --prefix=/usr/local/python3.3 <br/><br/>6。执行：make &amp;&amp; make install <br/><br/>7。此时已完成新版本的安装，但由于老版本还在系统中，所以需要将原来/usr/bin/python链接改为新的连接：a.先修改老的连接，执行：mv /usr/bin/python /usr/bin/python_bak。b.再建立新连接： ln -s /usr/local/python3.3/bin/python3.3 /usr/bin/python <br/><br/>8。查询python版本，执行：python <br/><br/>显示如下： <br/>Python 3.3.0 (default, Jan 16 2013, 17:52:44) <br/>[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux <br/>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. <br/>&gt;&gt;&gt; <br/>已安装成功了。恭喜你。<br/><br/>实际情况，一堆老版本，还得都给挪动一下，否则还是2.7啥的：<br/>/usr/bin/python2.4<br/>mv /usr/bin/python2.4&nbsp;&nbsp;/usr/bin/python2.4_bak<br/>ln -s /usr/local/python3.3/bin/python3.3 /usr/bin/python2.4 <br/><br/>/usr/local/bin/python2.7<br/>mv /usr/local/bin/python2.7 /usr/local/bin/python2.7_bak<br/>ln -s /usr/local/python3.3/bin/python3.3 /usr/local/bin/python2.7<br/><br/>实践来源：http://lovebeyond.iteye.com/blog/1770476<br/><br/><br/>最后，json显示结构化Ok了：<br/>[root@test Python-3.3.0]# echo &#039;&#123;&quot;status&quot;:200,&quot;data&quot;:[&#123;&quot;id&quot;:1000,&quot;name&quot;:&quot;John&quot;&#125;,&#123;&quot;id&quot;:1004,&quot;name&quot;:&quot;Tom&quot;&#125;]&#125;&#039;&#124;python -mjson.tool<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;data&quot;: [<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;id&quot;: 1000, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;name&quot;: &quot;John&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;id&quot;: 1004, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;name&quot;: &quot;Tom&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;], <br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;status&quot;: 200<br/>&#125;<br/><br/>再结合Curl这个命令行显示一把，实践如下：<br/>cat json.php <br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
echo &lt;&lt;&lt;EOF
&nbsp;&nbsp;&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;status&quot;:200,&nbsp;&nbsp;&quot;data&quot;:&nbsp;&nbsp;[&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;id&quot;:1000,&nbsp;&nbsp;&quot;name&quot;:&quot;John&quot;&nbsp;&nbsp;&#125;,&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;id&quot;:1004,&nbsp;&nbsp;&quot;name&quot;:&quot;Tom&quot;&nbsp;&nbsp;&#125;&nbsp;&nbsp;]&nbsp;&nbsp;&#125;&nbsp;&nbsp;
EOF;
</textarea><br/>shell访问，直接访问json是一行，后面直接加上python的解析后变成了一个格式化的json串显示出来了，达到了目的，如下：<br/>[root@test tools.jackxiang.com]# curl -H&quot;Host:t43.jackxiang.com&quot; &quot;http://192.168.109.8/json.php&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;status&quot;:200,&nbsp;&nbsp;&quot;data&quot;:&nbsp;&nbsp;[&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;id&quot;:1000,&nbsp;&nbsp;&quot;name&quot;:&quot;John&quot;&nbsp;&nbsp;&#125;,&nbsp;&nbsp;&#123;&nbsp;&nbsp;&quot;id&quot;:1004,&nbsp;&nbsp;&quot;name&quot;:&quot;Tom&quot;&nbsp;&nbsp;&#125;&nbsp;&nbsp;]&nbsp;&nbsp;&#125;&nbsp;&nbsp;[root@test tools.jackxiang.com]# curl -H&quot;Host:t43.jackxiang.com&quot; &quot;http://192.168.109.8/json.php&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vi json.php <br/>[root@test tools.jackxiang.com]# curl -H&quot;Host:t43.jackxiang.com&quot; &quot;http://192.168.109.8/json.php&quot; &#124; python -mjson.tool&nbsp;&nbsp;<br/>&nbsp;&nbsp;% Total&nbsp;&nbsp;&nbsp;&nbsp;% Received % Xferd&nbsp;&nbsp;Average Speed&nbsp;&nbsp; Time&nbsp;&nbsp;&nbsp;&nbsp;Time&nbsp;&nbsp;&nbsp;&nbsp; Time&nbsp;&nbsp;Current<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dload&nbsp;&nbsp;Upload&nbsp;&nbsp; Total&nbsp;&nbsp; Spent&nbsp;&nbsp;&nbsp;&nbsp;Left&nbsp;&nbsp;Speed<br/>100&nbsp;&nbsp; 106&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp; 106&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;51381&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 --:--:-- --:--:-- --:--:--&nbsp;&nbsp;&nbsp;&nbsp; 0<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;data&quot;: [<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;id&quot;: 1000, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;name&quot;: &quot;John&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;id&quot;: 1004, <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;name&quot;: &quot;Tom&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;], <br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;status&quot;: 200<br/>&#125;<br/><br/><br/>最后，当python升级到3后，yum出现：except KeyboardInterrupt, e:<br/>问题：<br/>——————————————————————————————————<br/>[root@name user]# yum<br/>File &quot;/usr/bin/yum&quot;, line 30<br/>except KeyboardInterrupt, e:<br/>^<br/>原因：<br/>这是因为yum采用python作为命令解释器，这可以从/usr/bin/yum文件中第一行#!/usr/bin/python发现。而python版本之间兼容性不太好，使得2.X版本与3.0版本之间存在语法不一致问题。而CentOS 5自带的yum采用的是python2.4，当系统将python升级到2.6或3.0后，出现语法解释错误。<br/>解决办法：<br/>很简单，一是升级yum，一是修改yum的解释器为旧版本python2.4（如果你没有采用覆盖升级的话）<br/>升级yum的作法就不详述了；<br/>修改yum的解释器为旧版本python2.4：<br/>&nbsp;&nbsp;&nbsp;&nbsp; vi /usr/bin/yum<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp; 将第一行&quot;#!/usr/bin/python&quot; 改为 &quot;#!/usr/bin/python2.4&quot;即可,我自己是修改：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/bin/python2.4_bak&nbsp;&nbsp;//前面挪动到这儿了，实践是OK的~<br/><br/>摘自：http://blog.sina.com.cn/s/blog_67d6a2650100jiaw.html
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]通过命令行能不能打印易读的Json数据怎么办？接合windows使用curl命令输出json并格式化的方法。及升级CentOS下的python到3.3版本的步骤，升级后yum except KeyboardInterrupt, e: 错误。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>