Each script has its own expertise.
There is a time to achieve a work, the use of Shell,php,python look at the file type, inconvenient handover, looking also more trouble .
It is also necessary to reduce the number of file types.
Scenario encountered: The shell program needs to get information from the JSON and continue processing.
File, Json.txt
{ "name":"China", "Province": [{ "name":"Heilongjiang", "Cities": { " City": ["Harbin","Daqing"] } }, { "name":"Guangdong", "Cities": { " City": ["Guangzhou","Shenzhen","Zhuhai"] } } ]}
Python can be called directly from the shell (note the difference between load and loads)
cat json.txt |/usr/bin/python2. 7"import json; Import SYS; Obj=json.load (Sys.stdin); Print obj[' province '][1][' name '].encode (' utf-8 ')" Guangdong [email protected]:cat json.txt |/usr/bin/python2. 7 " import JSON, import sys, obj=json.load (sys.stdin), print obj[' province '][1][' cities ' [' City '][1].encode (' utf-8 ') )" Shenzhen
Other Links:
Http://www.cnblogs.com/xudong-bupt/p/6218140.html
Http://www.cnblogs.com/xudong-bupt/p/7291645.html
Shell command line execution python