Re: [问题] 撷取资料跟资料转换

楼主: kenduest (小州)   2016-10-24 19:36:36
※ 引述《asdrt (安静)》之铭言:
: {
: "id":"674579ca-8ae2-4f3c-8c2b-c8a28e106f75",
: "macAddr":"04000207",
: "data":"41303132352d3039302d31",
: "buff":"2016-10-24T04:15:58.133Z",
: "recv":"2016-10-24T04:15:57.000Z",
: "extra":{"gwip":"172.16.5.15",
: "gwid":"00001c497b3b8127",
: "repeater":"00000000ffffffff",
: "systype":4,
: "rssi":-123.2,
: "snr":-12.2}
: }
: 收到的资料并没有分行,想说能不能写个 shell 让他自动分行
: 目前只是把收到的资料利用 >> 写入到 txt 里面
: 想说如果可以自动分行
: 这样在资料撷取上也比较简单
分成多行是可以,但是你后续用 >> 写入附加到时候整个混在一起,这样可以解析吗?
单纯分成多行很简单,一般系统都有装 python 这个语言的直译器,那这样使用:
$ cat xxxx.json | python -m json.tool 即可。
像是:
$ cat file.json
{"current_user_url":"https://api.github.com/user","starred_url":"https://api.github.com/user/starred{/owner}{/repo}","starred_gists_url":"https://api.github.com/gists/starred","team_url":"https://api.github.com/teams","user_url":"https://api.github.com/users/{user}"}
$ cat file.json | python -m json.tool
{
"current_user_url": "https://api.github.com/user",
"starred_gists_url": "https://api.github.com/gists/starred",
"starred_url": "https://api.github.com/user/starred{/owner}{/repo}",
"team_url": "https://api.github.com/teams",
"user_url": "https://api.github.com/users/{user}"
}
都帮你排版排好了,也是多行输出。不过你的需求都多行放成一个档案了,解析上是另外一个层级问题了。
: 所以来请教说是否可以透过 , 来做为每一行的分行代表跟执行方式
: 另外想请问的是
: 中间"41303132352d3039302d31" 这一串是ascii code 16进位
: 有没有工具可以将 这一串转换回 string
: 以上
: 感谢
: OS :ubuntu 10.04 LTS
可以执行 python 命令进入互动模式,输入 "41303132352d3039302d31".decode('hex')
就可以得到:
A0125-090-1
最后推荐学一点程式语言有助于问题解决,python 这个 script 很好用可以解决很多需求。
作者: s58348292 (S58)   2016-10-24 20:44:00
真是好人!!
继续阅读
[问题] 租用网站主机及网址qazsd[问题] nginx的rewrite问题mathtku[问题] 撷取资料跟资料转换asdrt[问题] ssl设定的网站导向chaos012[心得] Raspberry Pi, VNC 心得lihgong[问题] [email protected]

Links booklink

Contact Us: admin [ a t ] ucptt.com