On 11.5.2012 0:12, Petr Laznovsky wrote:
> Anybody experienced parsing JSON? Need to periodically parse JSON data
> and store some values.
After some time spended with this, finaly got it. Any comments,
improvements? Go on, hit me....
@echo off & setlocal ENABLEDELAYEDEXPANSION
set file=c:\work\UBNTmon\clients.txt
::
for /f "tokens=1,* delims=:," %%a in (%file%) do (
if not "%%b"=="" call :dequote %%b
(for /f "tokens=* delims= " %%e in (%%a) do set atoken=%%e) 2>NUL
if "!atoken!"=="mac" set mac=!btoken!
if "!atoken!"=="name" set name=!btoken!
if "!atoken!"=="lastip" set ip=!btoken!
if "!atoken!"=="associd" set id=!btoken!
if "!atoken!"=="tx" set tx=!btoken!
if "!atoken!"=="rx" set rx=!btoken!
if "!atoken!"=="signal" set sig=!btoken!
if "!atoken!"=="ccq" set ccq=!btoken!
if "!atoken!"=="noisefloor" set noise=!btoken!
if "!atoken!"=="rx_bytes" set rxb=!btoken!
if "!atoken!"=="tx_bytes" set txb=!btoken!
if "!atoken!"=="signals" set
client;!id!=!mac!;!name!;!ip!;!tx!;!rx!;!sig!;!ccq!;!noise!;!rxb!;!txb!
)
goto end
::
:dequote
set btoken=%~1
GOTO:EOF
::
:end
set client
-------------------clients.txt begin-----------------------
[
{
"mac": "00:80:48:53:35:7E",
"name" : "WP54AG-Klient",
"lastip" : "10.12.34.235",
"associd" : 1,
"apwds" : 0,
"tx" : 48,
"rx" : 54,
"signal" : -42,
"ccq" : 99,
"idle" : 115,
"uptime" : 81074,
"ack" : 27,
"distance" : 0,
"txpower" : 50,
"noisefloor" : -94,
"airmax" : {
"priority" : 0,
"quality" : 0,
"capacity" : 0 },
"stats" : {
"rx_data" : 137551,
"rx_bytes" : 17407375,
"rx_pps" : 0,
"tx_data" : 228419,
"tx_bytes" : 308773034,
"tx_pps" : 0 },
"rates" : [ "6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M" ],
"signals" : [ 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
"mac": "00:15:6D:D6:29:5E",
"name" : "stud-vikt",
"lastip" : "10.12.48.194",
"associd" : 2,
"apwds" : 0,
"tx" : 48,
"rx" : 48,
"signal" : -66,
"ccq" : 99,
"idle" : 6,
"uptime" : 81074,
"ack" : 27,
"distance" : 0,
"txpower" : 50,
"noisefloor" : -94,
"airmax" : {
"priority" : 0,
"quality" : 0,
"capacity" : 0 },
"stats" : {
"rx_data" : 844961,
"rx_bytes" : 109697999,
"rx_pps" : 0,
"tx_data" : 1371947,
"tx_bytes" : 1762413900,
"tx_pps" : 0 },
"rates" : [ "6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M" ],
"signals" : [ 0, 0, 0, 0, 0, 0, -67, 0 ]
},
{
"mac": "00:80:48:5E:E7:92",
"name" : "spoluprace-vik",
"lastip" : "10.12.48.66",
"associd" : 3,
"apwds" : 0,
"tx" : 48,
"rx" : 6,
"signal" : -69,
"ccq" : 99,
"idle" : 43,
"uptime" : 81074,
"ack" : 27,
"distance" : 0,
"txpower" : 50,
"noisefloor" : -94,
"airmax" : {
"priority" : 0,
"quality" : 0,
"capacity" : 0 },
"stats" : {
"rx_data" : 362803,
"rx_bytes" : 311443098,
"rx_pps" : 0,
"tx_data" : 323813,
"tx_bytes" : 179045859,
"tx_pps" : 0 },
"rates" : [ "6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M" ],
"signals" : [ 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
"mac": "00:80:48:55:53:50",
"name" : "WP54AG - Klien",
"lastip" : "10.12.34.236",
"associd" : 4,
"apwds" : 0,
"tx" : 48,
"rx" : 54,
"signal" : -50,
"ccq" : 98,
"idle" : 0,
"uptime" : 81074,
"ack" : 27,
"distance" : 0,
"txpower" : 50,
"noisefloor" : -94,
"airmax" : {
"priority" : 0,
"quality" : 0,
"capacity" : 0 },
"stats" : {
"rx_data" : 2091984,
"rx_bytes" : 501980557,
"rx_pps" : 31,
"tx_data" : 2825851,
"tx_bytes" : 2780711348,
"tx_pps" : 34 },
"rates" : [ "6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M" ],
"signals" : [ 0, 0, 0, 0, 0, 0, -48, -50 ]
},
{
"mac": "00:80:48:5E:E7:B6",
"name" : "WP54AG",
"lastip" : "10.12.34.237",
"associd" : 5,
"apwds" : 0,
"tx" : 6,
"rx" : 0,
"signal" : -59,
"ccq" : 0,
"idle" : 49516,
"uptime" : 81074,
"ack" : 27,
"distance" : 0,
"txpower" : 50,
"noisefloor" : -94,
"airmax" : {
"priority" : 0,
"quality" : 0,
"capacity" : 0 },
"stats" : {
"rx_data" : 5,
"rx_bytes" : 246,
"rx_pps" : 0,
"tx_data" : 544,
"tx_bytes" : 270,
"tx_pps" : 0 },
"rates" : [ "6M", "9M", "12M", "18M", "24M", "36M", "48M", "54M" ],
"signals" : [ 0, 0, 0, 0, 0, 0, 0, 0 ]
}
]
---------------clients.txt end------------------------------