我需要在JSON中格式化默认的Accel-PPP输出,但我不是一位经验丰富的程序员,并希望获得有效的命令以获得处理时间。我找到了这个链接https://unix.stackexchange.com/questions/243484/how-do-i-convert-the-output-of-ps1-to-json。但默认输出与上述链接不同,如下所示:
ifname | username | calling-sid | rate-limit
----------+----------+-------------------+-------------
pppoe0 | joao | EC:22:80:A2:5E:D5 | 10240/1024
pppoe2 | pedro | C0:4A:00:88:E5:29 | 5120/1024
pppoe4 | maria | B0:4E:26:B1:75:7D | 5120/1024
我希望它看起来像这样:
[
{
"username":"joao",
"data":{
"ifname":"pppoe0",
"calling-sid":"EC:22:80:A2:5E:D5",
"rate-limit":"10240/1024"
}
},
{
"username":"pedro",
"data":{
"ifname":"pppoe2",
"calling-sid":"C0:4A:00:88:E5:29",
"rate-limit":"5120/1024"
}
},
{
"username":"maria",
"data":{
"ifname":"pppoe4",
"calling-sid":"B0:4E:26:B1:75:7D",
"rate-limit":"5120/1024"
}
}
]
答案 0 :(得分:0)
我制作了一个小shell脚本以JSON格式打印它:
public static Boolean isLocationEnabled(Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// This is new method provided in API 28
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return lm.isLocationEnabled();
} else {
// This is Deprecated in API 28
int mode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE,
Settings.Secure.LOCATION_MODE_OFF);
return (mode != Settings.Secure.LOCATION_MODE_OFF);
}
}
在CentOS 6.9中进行了测试,并在jsonlint中验证了JSON